Commit 08b1c9f9 authored by Kenton Varda's avatar Kenton Varda

Chrome does not handle the HTTP 408 status correctly, so just close the connection instead.

parent 220538bf
...@@ -1165,9 +1165,8 @@ KJ_TEST("HttpServer request timeout") { ...@@ -1165,9 +1165,8 @@ KJ_TEST("HttpServer request timeout") {
// Shouldn't hang! Should time out. // Shouldn't hang! Should time out.
server.listenHttp(kj::mv(pipe.ends[0])).wait(io.waitScope); server.listenHttp(kj::mv(pipe.ends[0])).wait(io.waitScope);
// Sends back 408 Request Timeout. // Closes the connection without sending anything.
KJ_EXPECT(pipe.ends[1]->readAllText().wait(io.waitScope) KJ_EXPECT(pipe.ends[1]->readAllText().wait(io.waitScope) == "");
.startsWith("HTTP/1.1 408 Request Timeout"));
} }
KJ_TEST("HttpServer pipeline timeout") { KJ_TEST("HttpServer pipeline timeout") {
......
...@@ -1773,15 +1773,17 @@ public: ...@@ -1773,15 +1773,17 @@ public:
return httpOutput.flush(); return httpOutput.flush();
} }
if (timedOut) { if (timedOut) {
if (firstRequest) { // Client took too long to send anything, so we're going to close the connection. In
return sendError(408, "Request Timeout", kj::str( // theory, we should send back an HTTP 408 error -- it is designed exactly for this
"ERROR: Your client took too long to send HTTP headers.")); // purpose. Alas, in practice, Google Chrome does not have any special handling for 408
} else { // errors -- it will assume the error is a response to the next request it tries to send,
// After the first request, we just close the connection if the client takes too long, // and will happily serve the error to the user. OTOH, if we simply close the connection,
// on the assumption that the client is intentionally trying to keep the connection // Chrome does the "right thing", apparently. (Though I'm not sure what happens if a
// around for reuse (not necessarily an error). // request is in-flight when we close... if it's a GET, the browser should retry. But if
return httpOutput.flush(); // it's a POST, retrying may be dangerous. This is why 408 exists -- it unambiguously
} // tells the client that it should retry.)
return httpOutput.flush();
} }
KJ_IF_MAYBE(req, request) { KJ_IF_MAYBE(req, request) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment