Browse Source

[mod_proxy] fall back to waiting for connection close if no message length indicator is found in HTTP/1.1 response

It seems this is actually allowed by the RFCs; although it is intended
as HTTP/1.0 backward compatibility, and HTTP/1.1 servers (backends)
really should do better.

Change-Id: I93265bfe7fae57beb10d70d3a4596c5cae7b51bd
master
Stefan Bühler 2 weeks ago
parent
commit
b41e02860c
  1. 12
      src/main/stream_http_response.c
  2. 14
      tests/t-mod-proxy.py

12
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;
}
}
}

14
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):

Loading…
Cancel
Save