From 5512fa1b86f31feb16078b3bfbda888dfcf5de27 Mon Sep 17 00:00:00 2001 From: Jeff Trawick Date: Fri, 11 Apr 2014 17:07:18 +0000 Subject: [PATCH] mod_proxy_http: Add detach_backend hook. The immediate use is for a SSL-related module which works on the backend proxy connection to be able to "leak" information into the client r for logging. This could be useful with other proxy scheme handlers. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1586719 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 3 +++ include/ap_mmn.h | 3 ++- modules/proxy/mod_proxy.c | 4 ++++ modules/proxy/mod_proxy.h | 9 +++++++++ modules/proxy/mod_proxy_http.c | 13 +++++++++++++ 5 files changed, 31 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 34e86044c7..b49d831333 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,9 @@ -*- coding: utf-8 -*- Changes with Apache 2.5.0 + *) mod_proxy_http: Add detach_backend hook (potentially usable + in other proxy scheme handlers). [Jeff Trawick] + *) mod_deflate: Add DeflateAlterETag to control how the ETag is modified. The 'NoChange' parameter mimics 2.2.x behavior. PR 45023, PR 39727. [Eric Covener] diff --git a/include/ap_mmn.h b/include/ap_mmn.h index 5b82a4420c..e2ea31a168 100644 --- a/include/ap_mmn.h +++ b/include/ap_mmn.h @@ -449,6 +449,7 @@ * 20131230.2 (2.5.0-dev) Prefix REWRITE_REDIRECT_HANDLER_NAME in mod_rewrite.h * 20140207.0 (2.5.0-dev) Support for slaved connections in core.c * 20140207.1 (2.5.0-dev) Add SSL reusable SNI to mod_proxy.h's proxy_conn_rec + * 20140207.2 (2.5.0-dev) Add proxy detach_backend hook */ #define MODULE_MAGIC_COOKIE 0x41503235UL /* "AP25" */ @@ -456,7 +457,7 @@ #ifndef MODULE_MAGIC_NUMBER_MAJOR #define MODULE_MAGIC_NUMBER_MAJOR 20140207 #endif -#define MODULE_MAGIC_NUMBER_MINOR 1 /* 0...n */ +#define MODULE_MAGIC_NUMBER_MINOR 2 /* 0...n */ /** * Determine if the server's current MODULE_MAGIC_NUMBER is at least a diff --git a/modules/proxy/mod_proxy.c b/modules/proxy/mod_proxy.c index 1c6716b8bb..a084582704 100644 --- a/modules/proxy/mod_proxy.c +++ b/modules/proxy/mod_proxy.c @@ -2779,3 +2779,7 @@ APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(proxy, PROXY, int, request_status, (int *status, request_rec *r), (status, r), OK, DECLINED) +APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(proxy, PROXY, int, detach_backend, + (request_rec *r, proxy_conn_rec *backend), + (r, backend), OK, DECLINED) + diff --git a/modules/proxy/mod_proxy.h b/modules/proxy/mod_proxy.h index 930d95ab80..f55f42899e 100644 --- a/modules/proxy/mod_proxy.h +++ b/modules/proxy/mod_proxy.h @@ -512,6 +512,15 @@ APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, canon_handler, (request_rec *r, APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, create_req, (request_rec *r, request_rec *pr)) APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, fixups, (request_rec *r)) +/** + * Let modules perform processing when the connection to the origin is being + * detached from the request. + * @param r The client request + * @param backend The proxy representation of the backend connection + */ +APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, detach_backend, (request_rec *r, + proxy_conn_rec *backend)) + /** * pre request hook. * It will return the most suitable worker at the moment diff --git a/modules/proxy/mod_proxy_http.c b/modules/proxy/mod_proxy_http.c index fbe300122b..4dcc4b9f18 100644 --- a/modules/proxy/mod_proxy_http.c +++ b/modules/proxy/mod_proxy_http.c @@ -1309,6 +1309,7 @@ int ap_proxy_http_process_response(apr_pool_t * p, request_rec *r, apr_table_setn(r->notes, "proxy_timedout", "1"); ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01103) "read timeout"); if (do_100_continue) { + proxy_run_detach_backend(r, backend); return ap_proxyerror(r, HTTP_SERVICE_UNAVAILABLE, "Timeout on 100-Continue"); } } @@ -1341,6 +1342,7 @@ int ap_proxy_http_process_response(apr_pool_t * p, request_rec *r, /* Mark the backend connection for closing */ backend->close = 1; /* Need to return OK to avoid sending an error message */ + proxy_run_detach_backend(r, backend); return OK; } else if (!c->keepalives) { @@ -1350,6 +1352,7 @@ int ap_proxy_http_process_response(apr_pool_t * p, request_rec *r, " failed.", backend->hostname, backend->port); } + proxy_run_detach_backend(r, backend); return ap_proxyerror(r, HTTP_GATEWAY_TIME_OUT, "Error reading from remote server"); } @@ -1369,6 +1372,7 @@ int ap_proxy_http_process_response(apr_pool_t * p, request_rec *r, * if the status line was > 8192 bytes */ if ((major != 1) || (len >= sizeof(buffer)-1)) { + proxy_run_detach_backend(r, backend); return ap_proxyerror(r, HTTP_BAD_GATEWAY, apr_pstrcat(p, "Corrupt status line returned by remote " "server: ", buffer, NULL)); @@ -1427,6 +1431,7 @@ int ap_proxy_http_process_response(apr_pool_t * p, request_rec *r, r->headers_out = apr_table_make(r->pool,1); r->status = HTTP_BAD_GATEWAY; r->status_line = "bad gateway"; + proxy_run_detach_backend(r, backend); return r->status; } @@ -1624,6 +1629,7 @@ int ap_proxy_http_process_response(apr_pool_t * p, request_rec *r, (proxy_status != HTTP_NOT_MODIFIED)) { /* not 304 */ ap_discard_request_body(backend->r); } + proxy_run_detach_backend(r, backend); return proxy_status; } @@ -1778,6 +1784,7 @@ int ap_proxy_http_process_response(apr_pool_t * p, request_rec *r, * left waiting for a slow client to eventually * acknowledge the data. */ + proxy_run_detach_backend(r, backend); ap_proxy_release_connection(backend->worker->s->scheme, backend, r->server); /* Ensure that the backend is not reused */ @@ -1816,6 +1823,7 @@ int ap_proxy_http_process_response(apr_pool_t * p, request_rec *r, * left waiting for a slow client to eventually * acknowledge the data. */ + proxy_run_detach_backend(r, backend); ap_proxy_release_connection(backend->worker->s->scheme, backend, r->server); *backend_ptr = NULL; @@ -1833,6 +1841,10 @@ int ap_proxy_http_process_response(apr_pool_t * p, request_rec *r, * created from scpool and this pool can be freed before this brigade. */ apr_brigade_cleanup(bb); + if (*backend_ptr) { + proxy_run_detach_backend(r, backend); + } + /* See define of AP_MAX_INTERIM_RESPONSES for why */ if (interim_response >= AP_MAX_INTERIM_RESPONSES) { return ap_proxyerror(r, HTTP_BAD_GATEWAY, @@ -2003,6 +2015,7 @@ static int proxy_http_handler(request_rec *r, proxy_worker *worker, */ if ((status = ap_proxy_http_request(p, r, backend, worker, conf, uri, locurl, server_portstr)) != OK) { + proxy_run_detach_backend(r, backend); if ((status == HTTP_SERVICE_UNAVAILABLE) && worker->s->ping_timeout_set && worker->s->ping_timeout >= 0) { -- 2.40.0