From: Willy Tarreau Date: Tue, 16 Jun 2020 15:36:36 +0000 (+0200) Subject: MINOR: http: do not close connections anymore after internal responses X-Git-Tag: v2.2-dev10~39 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2c4dfaeff667b770802711051dd5c04a7f634af8;p=thirdparty%2Fhaproxy.git MINOR: http: do not close connections anymore after internal responses Since we dropped support for legacy mode, it's not the stream which deals with the connection but the mux, and there's no point in closing the client connection after most internal status codes. For example if the client gets a 401 or a 503 because a server doesn't respond, it makes no sense forcing the connection to close after reporting this status, because it's already done by the mux if the client asks for it or is not compatible with keep-alive. This current state was inherited from the early days but is still limiting the amount of client-side connection reuse in a number of circumstances (typically server-side errors). This change was planned for 2.1 but forgotten. The status codes for which the connection is not closed anymore are those that do not depend on the client side connection itself, which are all except 400 and 408. This could be backported to 2.1 but not further, in order to make sure legacy and HTX behave strictly similarly. --- diff --git a/src/http.c b/src/http.c index f8d78763e2..b798c5db92 100644 --- a/src/http.c +++ b/src/http.c @@ -179,7 +179,6 @@ const char *http_err_msgs[HTTP_ERR_SIZE] = { "HTTP/1.1 200 OK\r\n" "Content-length: 58\r\n" "Cache-Control: no-cache\r\n" - "Connection: close\r\n" "Content-Type: text/html\r\n" "\r\n" "

200 OK

\nService ready.\n\n", @@ -197,7 +196,6 @@ const char *http_err_msgs[HTTP_ERR_SIZE] = { "HTTP/1.1 401 Unauthorized\r\n" "Content-length: 112\r\n" "Cache-Control: no-cache\r\n" - "Connection: close\r\n" "Content-Type: text/html\r\n" "\r\n" "

401 Unauthorized

\nYou need a valid user and password to access this content.\n\n", @@ -206,7 +204,6 @@ const char *http_err_msgs[HTTP_ERR_SIZE] = { "HTTP/1.1 403 Forbidden\r\n" "Content-length: 93\r\n" "Cache-Control: no-cache\r\n" - "Connection: close\r\n" "Content-Type: text/html\r\n" "\r\n" "

403 Forbidden

\nRequest forbidden by administrative rules.\n\n", @@ -215,7 +212,6 @@ const char *http_err_msgs[HTTP_ERR_SIZE] = { "HTTP/1.1 404 Not Found\r\n" "Content-length: 83\r\n" "Cache-Control: no-cache\r\n" - "Connection: close\r\n" "Content-Type: text/html\r\n" "\r\n" "

404 Not Found

\nThe resource could not be found.\n\n", @@ -224,7 +220,6 @@ const char *http_err_msgs[HTTP_ERR_SIZE] = { "HTTP/1.1 405 Method Not Allowed\r\n" "Content-length: 146\r\n" "Cache-Control: no-cache\r\n" - "Connection: close\r\n" "Content-Type: text/html\r\n" "\r\n" "

405 Method Not Allowed

\nA request was made of a resource using a request method not supported by that resource\n\n", @@ -233,7 +228,6 @@ const char *http_err_msgs[HTTP_ERR_SIZE] = { "HTTP/1.1 407 Unauthorized\r\n" "Content-length: 112\r\n" "Cache-Control: no-cache\r\n" - "Connection: close\r\n" "Content-Type: text/html\r\n" "\r\n" "

407 Unauthorized

\nYou need a valid user and password to access this content.\n\n", @@ -251,7 +245,6 @@ const char *http_err_msgs[HTTP_ERR_SIZE] = { "HTTP/1.1 410 Gone\r\n" "Content-length: 114\r\n" "Cache-Control: no-cache\r\n" - "Connection: close\r\n" "Content-Type: text/html\r\n" "\r\n" "

410 Gone

\nThe resource is no longer available and will not be available again.\n\n", @@ -260,7 +253,6 @@ const char *http_err_msgs[HTTP_ERR_SIZE] = { "HTTP/1.1 421 Misdirected Request\r\n" "Content-length: 104\r\n" "Cache-Control: no-cache\r\n" - "Connection: close\r\n" "Content-Type: text/html\r\n" "\r\n" "

421 Misdirected Request

\nRequest sent to a non-authoritative server.\n\n", @@ -269,7 +261,6 @@ const char *http_err_msgs[HTTP_ERR_SIZE] = { "HTTP/1.1 425 Too Early\r\n" "Content-length: 80\r\n" "Cache-Control: no-cache\r\n" - "Connection: close\r\n" "Content-Type: text/html\r\n" "\r\n" "

425 Too Early

\nYour browser sent early data.\n\n", @@ -278,7 +269,6 @@ const char *http_err_msgs[HTTP_ERR_SIZE] = { "HTTP/1.1 429 Too Many Requests\r\n" "Content-length: 117\r\n" "Cache-Control: no-cache\r\n" - "Connection: close\r\n" "Content-Type: text/html\r\n" "\r\n" "

429 Too Many Requests

\nYou have sent too many requests in a given amount of time.\n\n", @@ -287,7 +277,6 @@ const char *http_err_msgs[HTTP_ERR_SIZE] = { "HTTP/1.1 500 Internal Server Error\r\n" "Content-length: 96\r\n" "Cache-Control: no-cache\r\n" - "Connection: close\r\n" "Content-Type: text/html\r\n" "\r\n" "

500 Internal Server Error

\nAn internal server error occured.\n\n", @@ -296,7 +285,6 @@ const char *http_err_msgs[HTTP_ERR_SIZE] = { "HTTP/1.1 502 Bad Gateway\r\n" "Content-length: 107\r\n" "Cache-Control: no-cache\r\n" - "Connection: close\r\n" "Content-Type: text/html\r\n" "\r\n" "

502 Bad Gateway

\nThe server returned an invalid or incomplete response.\n\n", @@ -305,7 +293,6 @@ const char *http_err_msgs[HTTP_ERR_SIZE] = { "HTTP/1.1 503 Service Unavailable\r\n" "Content-length: 107\r\n" "Cache-Control: no-cache\r\n" - "Connection: close\r\n" "Content-Type: text/html\r\n" "\r\n" "

503 Service Unavailable

\nNo server is available to handle this request.\n\n", @@ -314,11 +301,9 @@ const char *http_err_msgs[HTTP_ERR_SIZE] = { "HTTP/1.1 504 Gateway Time-out\r\n" "Content-length: 92\r\n" "Cache-Control: no-cache\r\n" - "Connection: close\r\n" "Content-Type: text/html\r\n" "\r\n" "

504 Gateway Time-out

\nThe server didn't respond in time.\n\n", - }; const struct ist http_known_methods[HTTP_METH_OTHER] = {