From 169d8d3608fb90e4f00ec77d149788e59a6fc8d5 Mon Sep 17 00:00:00 2001 From: Glenn Strauss Date: Mon, 9 Nov 2020 18:18:18 -0500 Subject: [PATCH] [core] accept "HTTP/2.0", "HTTP/3.0" from backends (fixes #3031) accept "HTTP/2.0" and "HTTP/3.0" NPH from naive non-proxy backends (thx flynn) x-ref: "uwsgi fails with HTTP/2" https://redmine.lighttpd.net/issues/3031 --- src/http-header-glue.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/http-header-glue.c b/src/http-header-glue.c index ec8cd9bc..5772c735 100644 --- a/src/http-header-glue.c +++ b/src/http-header-glue.c @@ -1091,9 +1091,11 @@ static int http_response_process_headers(request_st * const r, http_response_opt ns[0] = '\0'; if (ns > s && ns[-1] == '\r') ns[-1] = '\0'; - if (0 == line && 0 == strncmp(s, "HTTP/1.", 7)) { + if (0 == line && (ns - s) >= 12 && 0 == memcmp(s, "HTTP/", 5)) { /* non-parsed headers ... we parse them anyway */ - if ((s[7] == '1' || s[7] == '0') && s[8] == ' ') { + /* (accept HTTP/2.0 and HTTP/3.0 from naive non-proxy backends) */ + if ((s[5] == '1' || opts->backend != BACKEND_PROXY) && s[6] == '.' + && (s[7] == '1' || s[7] == '0') && s[8] == ' ') { /* after the space should be a status code for us */ int status = http_header_str_to_code(s+9); if (status >= 100 && status < 1000) { @@ -1303,8 +1305,8 @@ handler_t http_response_parse_headers(request_st * const r, http_response_opts * do { blen = buffer_string_length(b); - /*("HTTP/1.1 200 " is at least 13 chars + \r\n)*/ - const int is_nph = (blen > 12 && 0 == memcmp(b->ptr, "HTTP/1.", 7)); + /*("HTTP/1.1 200 " is at least 13 chars + \r\n, but accept w/o final ' ')*/ + const int is_nph = (blen >= 12 && 0 == memcmp(b->ptr, "HTTP/", 5)); int is_header_end = 0; uint32_t i = 0;