From d79b9a03c5d228dfc13d4069f37d8889c62cba16 Mon Sep 17 00:00:00 2001 From: Jeff Trawick Date: Wed, 25 Sep 2013 14:29:02 +0000 Subject: [PATCH] mod_proxy: Add ap_connection_reusable() for checking if a connection is reusable as of this point in processing. mod_proxy_fcgi uses the new API to determine if FCGI_CONN_CLOSE should be enabled, but that doesn't change existing behavior since the connection is currently marked for closure elsewhere in the module. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1526189 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 3 +++ include/ap_mmn.h | 3 ++- modules/proxy/mod_proxy.h | 11 +++++++++++ modules/proxy/mod_proxy_fcgi.c | 4 +++- modules/proxy/proxy_util.c | 9 ++++++++- 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index 232e773708..bd7bedc48b 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,9 @@ -*- coding: utf-8 -*- Changes with Apache 2.5.0 + *) mod_proxy: Add ap_connection_reusable() for checking if a connection + is reusable as of this point in processing. [Jeff Trawick] + *) mod_ssl: drop support for export-grade ciphers with ephemeral RSA keys, and unconditionally disable aNULL, eNULL and EXP ciphers (not overridable via SSLCipherSuite). [Kaspar Brand] diff --git a/include/ap_mmn.h b/include/ap_mmn.h index a7f5fa5c32..baee00df21 100644 --- a/include/ap_mmn.h +++ b/include/ap_mmn.h @@ -440,6 +440,7 @@ * 20130702.3 (2.5.0-dev) Add util_fcgi.h, FastCGI protocol support * 20130903.0 (2.5.0-dev) Changes sizeof(worker_score) in scoreboard * 20130924.0 (2.5.0-dev) Add ap_errorlog_provider + * 20130924.1 (2.5.0-dev) Add ap_proxy_connection_reusable() */ #define MODULE_MAGIC_COOKIE 0x41503235UL /* "AP25" */ @@ -447,7 +448,7 @@ #ifndef MODULE_MAGIC_NUMBER_MAJOR #define MODULE_MAGIC_NUMBER_MAJOR 20130924 #endif -#define MODULE_MAGIC_NUMBER_MINOR 0 /* 0...n */ +#define MODULE_MAGIC_NUMBER_MINOR 1 /* 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 e36f3f734c..8dce385dcb 100644 --- a/modules/proxy/mod_proxy.h +++ b/modules/proxy/mod_proxy.h @@ -857,6 +857,17 @@ PROXY_DECLARE(int) ap_proxy_connect_backend(const char *proxy_function, 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 ee7029002c..56c9c37456 100644 --- a/modules/proxy/mod_proxy_fcgi.c +++ b/modules/proxy/mod_proxy_fcgi.c @@ -193,7 +193,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/proxy_util.c b/modules/proxy/proxy_util.c index 58fa00d9a7..d2f7b70e8e 100644 --- a/modules/proxy/proxy_util.c +++ b/modules/proxy/proxy_util.c @@ -1334,6 +1334,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; @@ -1362,7 +1369,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)); -- 2.49.0