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") {
// Shouldn't hang! Should time out.
server.listenHttp(kj::mv(pipe.ends[0])).wait(io.waitScope);
// Sends back 408 Request Timeout.
KJ_EXPECT(pipe.ends[1]->readAllText().wait(io.waitScope)
.startsWith("HTTP/1.1 408 Request Timeout"));
// Closes the connection without sending anything.
KJ_EXPECT(pipe.ends[1]->readAllText().wait(io.waitScope) == "");
}
KJ_TEST("HttpServer pipeline timeout") {
......
......@@ -1773,16 +1773,18 @@ public:
return httpOutput.flush();
}
if (timedOut) {
if (firstRequest) {
return sendError(408, "Request Timeout", kj::str(
"ERROR: Your client took too long to send HTTP headers."));
} else {
// After the first request, we just close the connection if the client takes too long,
// on the assumption that the client is intentionally trying to keep the connection
// around for reuse (not necessarily an error).
// Client took too long to send anything, so we're going to close the connection. In
// theory, we should send back an HTTP 408 error -- it is designed exactly for this
// purpose. Alas, in practice, Google Chrome does not have any special handling for 408
// errors -- it will assume the error is a response to the next request it tries to send,
// and will happily serve the error to the user. OTOH, if we simply close the connection,
// Chrome does the "right thing", apparently. (Though I'm not sure what happens if a
// request is in-flight when we close... if it's a GET, the browser should retry. But if
// 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) {
currentMethod = req->method;
......
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