From: Ryan Bloom Date: Tue, 16 Oct 2001 05:18:39 +0000 (+0000) Subject: Cleanup the proxy code that creates a request to the origin X-Git-Tag: 2.0.27~132 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e31a688ce552caa4d6e7dddbd1228c3ca9513ee2;p=thirdparty%2Fapache%2Fhttpd.git Cleanup the proxy code that creates a request to the origin server. This change adds an optional hook, which allows modules to gain control while the request is created if the proxy module is loaded. The purpose of this hook is to allow modules to add input and/or output filters to the request to the origin. While I was at it, I made the core use this hook, so that proxy request creation uses some of the code from the core. This can still be greatly improved, but this is a good start. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@91486 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index bafbfb721e7..0872d99ffb7 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,14 @@ Changes with Apache 2.0.27-dev + *) Cleanup the proxy code that creates a request to the origin + server. This change adds an optional hook, which allows modules + to gain control while the request is created if the proxy module + is loaded. The purpose of this hook is to allow modules to add + input and/or output filters to the request to the origin. While + I was at it, I made the core use this hook, so that proxy request + creation uses some of the code from the core. This can still be + greatly improved, but this is a good start. [Ryan Bloom] + Changes with Apache 2.0.26 *) Port the MaxClients changes from the worker MPM to the threaded diff --git a/configure.in b/configure.in index abbda853b6d..de53272bbc8 100644 --- a/configure.in +++ b/configure.in @@ -98,9 +98,9 @@ dnl then we are running in VPATH mode. if test "$abs_builddir" != "$abs_srcdir"; then USE_VPATH=1 - APR_ADDTO(INCLUDES, [-I. -I\$(srcdir) -I\$(top_builddir)/os/\$(OS_DIR) -I\$(top_srcdir)/os/\$(OS_DIR) -I\$(top_builddir)/server/mpm/\$(MPM_NAME) -I\$(top_srcdir)/server/mpm/\$(MPM_NAME) -I\$(top_builddir)/modules/http -I\$(top_srcdir)/modules/http -I\$(top_builddir)/include -I\$(top_srcdir)/include -I\$(top_builddir)/srclib/apr/include -I\$(top_srcdir)/srclib/apr/include -I\$(top_builddir)/srclib/apr-util/include -I\$(top_srcdir)/srclib/apr-util/include]) + APR_ADDTO(INCLUDES, [-I. -I\$(srcdir) -I\$(top_builddir)/os/\$(OS_DIR) -I\$(top_srcdir)/os/\$(OS_DIR) -I\$(top_builddir)/server/mpm/\$(MPM_NAME) -I\$(top_srcdir)/server/mpm/\$(MPM_NAME) -I\$(top_builddir)/modules/http -I\$(top_srcdir)/modules/http -I\$(top_srcdir)/modules/proxy -I\$(top_builddir)/include -I\$(top_srcdir)/include -I\$(top_builddir)/srclib/apr/include -I\$(top_srcdir)/srclib/apr/include -I\$(top_builddir)/srclib/apr-util/include -I\$(top_srcdir)/srclib/apr-util/include]) else - APR_ADDTO(INCLUDES, [-I. -I\$(top_srcdir)/os/\$(OS_DIR) -I\$(top_srcdir)/server/mpm/\$(MPM_NAME) -I\$(top_srcdir)/modules/http -I\$(top_srcdir)/include -I\$(top_srcdir)/srclib/apr/include -I\$(top_srcdir)/srclib/apr-util/include]) + APR_ADDTO(INCLUDES, [-I. -I\$(top_srcdir)/os/\$(OS_DIR) -I\$(top_srcdir)/server/mpm/\$(MPM_NAME) -I\$(top_srcdir)/modules/http -I\$(top_srcdir)/modules/proxy -I\$(top_srcdir)/include -I\$(top_srcdir)/srclib/apr/include -I\$(top_srcdir)/srclib/apr-util/include]) fi echo $ac_n "${nl}Applying OS-specific hints for httpd ...${nl}" diff --git a/modules/proxy/mod_proxy.h b/modules/proxy/mod_proxy.h index 7aa95d45840..5b7a11d449d 100644 --- a/modules/proxy/mod_proxy.h +++ b/modules/proxy/mod_proxy.h @@ -237,6 +237,8 @@ APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, scheme_handler, (request_rec *r, APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, canon_handler, (request_rec *r, char *url)) +APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, create_req, (request_rec *r, request_rec *pr)) + /* proxy_util.c */ PROXY_DECLARE(request_rec *)ap_proxy_make_fake_req(conn_rec *c, request_rec *r); diff --git a/modules/proxy/proxy_util.c b/modules/proxy/proxy_util.c index 9dab21388f7..3f483026899 100644 --- a/modules/proxy/proxy_util.c +++ b/modules/proxy/proxy_util.c @@ -65,6 +65,10 @@ static int proxy_match_domainname(struct dirconn_entry *This, request_rec *r); static int proxy_match_hostname(struct dirconn_entry *This, request_rec *r); static int proxy_match_word(struct dirconn_entry *This, request_rec *r); +APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(proxy, AP, int, create_req, + (request_rec *r, request_rec *pr), (r, pr), + OK, DECLINED) + /* already called in the knowledge that the characters are hex digits */ PROXY_DECLARE(int) ap_proxy_hex2c(const char *x) { @@ -359,7 +363,6 @@ PROXY_DECLARE(const char *) PROXY_DECLARE(request_rec *)ap_proxy_make_fake_req(conn_rec *c, request_rec *r) { request_rec *rp = apr_pcalloc(c->pool, sizeof(*r)); - core_request_config *req_cfg; rp->pool = c->pool; rp->status = HTTP_OK; @@ -373,15 +376,11 @@ PROXY_DECLARE(request_rec *)ap_proxy_make_fake_req(conn_rec *c, request_rec *r) rp->server = r->server; rp->request_time = r->request_time; rp->connection = c; - rp->output_filters=NULL; - rp->input_filters=NULL; rp->output_filters = c->output_filters; rp->input_filters = c->input_filters; rp->request_config = ap_create_request_config(c->pool); - req_cfg = apr_pcalloc(rp->pool, sizeof(core_request_config)); - req_cfg->bb = apr_brigade_create(c->pool); - ap_set_module_config(rp->request_config, &core_module, req_cfg); + proxy_run_create_req(r, rp); return rp; } diff --git a/server/core.c b/server/core.c index cddac0942fd..65d2bacc080 100644 --- a/server/core.c +++ b/server/core.c @@ -88,6 +88,7 @@ #include "mpm_common.h" #include "scoreboard.h" #include "mod_core.h" +#include "mod_proxy.h" /* LimitXMLRequestBody handling */ @@ -3230,6 +3231,11 @@ static int core_create_req(request_rec *r) return OK; } +static int core_create_proxy_req(request_rec *r, request_rec *pr) +{ + core_create_req(pr); +} + static void register_hooks(apr_pool_t *p) { ap_hook_post_config(core_post_config,NULL,NULL,APR_HOOK_REALLY_FIRST); @@ -3242,6 +3248,8 @@ static void register_hooks(apr_pool_t *p) ap_hook_fixups(core_override_type,NULL,NULL,APR_HOOK_REALLY_FIRST); ap_hook_access_checker(do_nothing,NULL,NULL,APR_HOOK_REALLY_LAST); ap_hook_create_request(core_create_req, NULL, NULL, APR_HOOK_MIDDLE); + APR_OPTIONAL_HOOK(proxy, create_req, core_create_proxy_req, NULL, NULL, + APR_HOOK_MIDDLE); ap_hook_pre_mpm(ap_create_scoreboard, NULL, NULL, APR_HOOK_MIDDLE); /* register the core's insert_filter hook and register core-provided