diff --git a/src/main/stream_http_response.c b/src/main/stream_http_response.c index dfe4ca6..2981f0c 100644 --- a/src/main/stream_http_response.c +++ b/src/main/stream_http_response.c @@ -156,9 +156,15 @@ static void check_response_header(liStreamHttpResponse* shr) { } if (!shr->wait_for_close && shr->content_length < 0) { - VR_ERROR(shr->vr, "%s", "Backend: need chunked transfer-encoding or content-length for keepalive connections"); - li_vrequest_error(shr->vr); - return; + if (LI_HTTP_VERSION_1_1 == shr->parse_response_ctx.http_version) { + /* Fallback to waiting for connection close */ + VR_DEBUG(shr->vr, "%s", "HTTP/1.1 response: no clean message length indicator, fall back to waiting for connection close"); + shr->wait_for_close = TRUE; + } else { + VR_ERROR(shr->vr, "%s", "Backend: need chunked transfer-encoding or content-length for keepalive connections"); + li_vrequest_error(shr->vr); + return; + } } } diff --git a/tests/t-mod-proxy.py b/tests/t-mod-proxy.py index ab971a6..ea58eca 100644 --- a/tests/t-mod-proxy.py +++ b/tests/t-mod-proxy.py @@ -41,6 +41,10 @@ class HttpBackendHandler(socketserver.StreamRequestHandler): time.sleep(0.1) self.wfile.write(b"\r\n0\r\n\r\n") continue + if reqline[1].startswith("/nolength"): + self.wfile.write(b"HTTP/1.1 200 OK\r\n\r\nHello world") + self.finish() + return # send response resp_body = reqline[1].encode('utf-8') @@ -130,6 +134,15 @@ class TestBackendDelayedChunk(CurlRequest): backend_proxy; """ +class TestBackendNoLength(CurlRequest): + URL = "/nolength" + EXPECT_RESPONSE_BODY = "Hello world" + EXPECT_RESPONSE_CODE = 200 + no_docroot = True + config = """ +backend_proxy; +""" + class Test(GroupTest): group = [ TestSimple, @@ -138,6 +151,7 @@ class Test(GroupTest): TestBackendForcedKeepalive, TestBackendUpgrade, TestBackendDelayedChunk, + TestBackendNoLength, ] def Prepare(self):