From: Jeff Trawick Date: Wed, 15 Apr 2015 17:50:46 +0000 (+0000) Subject: mod_proxy_http: Use the "Connection: close" header for requests to X-Git-Tag: 2.4.13~225 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=14afe13363cdfade47d34263723647c76c7f6c7e;p=apache mod_proxy_http: Use the "Connection: close" header for requests to backends not recycling connections (disablereuse), including the default reverse and forward proxies. Submitted by: ylavic (and trawick for an old helper function) Reviewed by: rjung, covener git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1673896 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index 48dec809fd..88d6127146 100644 --- a/CHANGES +++ b/CHANGES @@ -12,6 +12,13 @@ Changes with Apache 2.4.13 calls r:wsupgrade() can cause a child process crash. [Edward Lu ] + *) mod_proxy_http: Use the "Connection: close" header for requests to + backends not recycling connections (disablereuse), including the default + reverse and forward proxies. [Yann Ylavic] + + *) mod_proxy: Add ap_connection_reusable() for checking if a connection + is reusable as of this point in processing. [Jeff Trawick] + *) core_filters: restore/disable TCP_NOPUSH option after non-blocking sendfile. [Yann Ylavic] diff --git a/STATUS b/STATUS index 29443368bd..45606a7612 100644 --- a/STATUS +++ b/STATUS @@ -105,14 +105,6 @@ RELEASE SHOWSTOPPERS: PATCHES ACCEPTED TO BACKPORT FROM TRUNK: [ start all new proposals below, under PATCHES PROPOSED. ] - *) mod_proxy_http: Use the "Connection: close" header for requests to - backends not recycling connections (disablereuse), including the default - reverse and forward proxies. - trunk patch: http://svn.apache.org/r1526189 - http://svn.apache.org/r1658765 - 2.4.x patch: http://people.apache.org/~ylavic/httpd-2.4.x-ap_proxy_connection_reusable.patch - +1: ylavic, rjung, covener - *) mod_ssl: Protect ENGINE_CTRL_CHIL_SET_FORKCHECK macro with a featue check for libressl. trunk patch: http://svn.apache.org/r1673455 diff --git a/include/ap_mmn.h b/include/ap_mmn.h index ea3d71ee17..fbd7e4c7b0 100644 --- a/include/ap_mmn.h +++ b/include/ap_mmn.h @@ -441,6 +441,7 @@ * 20120211.43 (2.4.13-dev) Add keep_alive_timeout_set to server_rec * 20120211.44 (2.4.13-dev) Add cgi_pass_auth and AP_CGI_PASS_AUTH_* to * core_dir_config + * 20120211.45 (2.4.13-dev) Add ap_proxy_connection_reusable() */ #define MODULE_MAGIC_COOKIE 0x41503234UL /* "AP24" */ @@ -448,7 +449,7 @@ #ifndef MODULE_MAGIC_NUMBER_MAJOR #define MODULE_MAGIC_NUMBER_MAJOR 20120211 #endif -#define MODULE_MAGIC_NUMBER_MINOR 44 /* 0...n */ +#define MODULE_MAGIC_NUMBER_MINOR 45 /* 0...n */ /** * Determine if the server's current MODULE_MAGIC_NUMBER is at least a diff --git a/modules/proxy/mod_proxy.h b/modules/proxy/mod_proxy.h index 89f5c0951a..f54c6b3ee7 100644 --- a/modules/proxy/mod_proxy.h +++ b/modules/proxy/mod_proxy.h @@ -889,6 +889,17 @@ PROXY_DECLARE(apr_status_t) ap_proxy_connect_uds(apr_socket_t *sock, PROXY_DECLARE(int) ap_proxy_connection_create(const char *proxy_function, proxy_conn_rec *conn, conn_rec *c, server_rec *s); + +/** + * Determine if proxy connection can potentially be reused at the + * end of this request. + * @param conn proxy connection + * @return non-zero if reusable, 0 otherwise + * @note Even if this function returns non-zero, the connection may + * be subsequently marked for closure. + */ +PROXY_DECLARE(int) ap_proxy_connection_reusable(proxy_conn_rec *conn); + /** * Signal the upstream chain that the connection to the backend broke in the * middle of the response. This is done by sending an error bucket with diff --git a/modules/proxy/mod_proxy_fcgi.c b/modules/proxy/mod_proxy_fcgi.c index 4a06fd133e..0e33545d78 100644 --- a/modules/proxy/mod_proxy_fcgi.c +++ b/modules/proxy/mod_proxy_fcgi.c @@ -225,7 +225,9 @@ static apr_status_t send_begin_request(proxy_conn_rec *conn, ap_fcgi_fill_in_header(&header, AP_FCGI_BEGIN_REQUEST, request_id, sizeof(abrb), 0); - ap_fcgi_fill_in_request_body(&brb, AP_FCGI_RESPONDER, AP_FCGI_KEEP_CONN); + ap_fcgi_fill_in_request_body(&brb, AP_FCGI_RESPONDER, + ap_proxy_connection_reusable(conn) + ? AP_FCGI_KEEP_CONN : 0); ap_fcgi_header_to_array(&header, farray); ap_fcgi_begin_request_body_to_array(&brb, abrb); diff --git a/modules/proxy/mod_proxy_http.c b/modules/proxy/mod_proxy_http.c index 9ca3917674..7665f828ce 100644 --- a/modules/proxy/mod_proxy_http.c +++ b/modules/proxy/mod_proxy_http.c @@ -922,7 +922,7 @@ skip_body: * otherwise sent Connection: Keep-Alive. */ if (!force10) { - if (p_conn->close) { + if (!ap_proxy_connection_reusable(p_conn)) { buf = apr_pstrdup(p, "Connection: close" CRLF); } else { diff --git a/modules/proxy/proxy_util.c b/modules/proxy/proxy_util.c index e47a5a0f36..734e4abe66 100644 --- a/modules/proxy/proxy_util.c +++ b/modules/proxy/proxy_util.c @@ -1351,6 +1351,13 @@ static void init_conn_pool(apr_pool_t *p, proxy_worker *worker) worker->cp = cp; } +PROXY_DECLARE(int) ap_proxy_connection_reusable(proxy_conn_rec *conn) +{ + proxy_worker *worker = conn->worker; + + return ! (conn->close || !worker->s->is_address_reusable || worker->s->disablereuse); +} + static apr_status_t connection_cleanup(void *theconn) { proxy_conn_rec *conn = (proxy_conn_rec *)theconn; @@ -1379,7 +1386,7 @@ static apr_status_t connection_cleanup(void *theconn) } /* determine if the connection need to be closed */ - if (conn->close || !worker->s->is_address_reusable || worker->s->disablereuse) { + if (!ap_proxy_connection_reusable(conn)) { apr_pool_t *p = conn->pool; apr_pool_clear(p); conn = apr_pcalloc(p, sizeof(proxy_conn_rec));