From: Jim Jagielski Date: Sat, 16 Nov 2013 20:13:48 +0000 (+0000) Subject: We were not being consistent between http and others X-Git-Tag: 2.5.0-alpha~4850 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bb76893cfbcb2bcfb59277daae6525f250fe617d;p=apache We were not being consistent between http and others if we added the default port or not during the canonizing phase... Baseline the http method (don't add unless the port provided isn't the default). git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1542562 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/proxy/mod_proxy.h b/modules/proxy/mod_proxy.h index 09384cf3ef..25b19b4947 100644 --- a/modules/proxy/mod_proxy.h +++ b/modules/proxy/mod_proxy.h @@ -1014,6 +1014,13 @@ PROXY_DECLARE(int) ap_proxy_is_socket_connected(apr_socket_t *socket); */ int ap_proxy_lb_workers(void); +/** + * Return the port number of a known scheme (eg: http -> 80). + * @param scheme scheme to test + * @return port number or 0 if unknown + */ +PROXY_DECLARE(apr_port_t) ap_proxy_port_of_scheme(const char *scheme); + extern module PROXY_DECLARE_DATA proxy_module; #endif /*MOD_PROXY_H*/ diff --git a/modules/proxy/mod_proxy_ajp.c b/modules/proxy/mod_proxy_ajp.c index 9e627b4510..02169c42e3 100644 --- a/modules/proxy/mod_proxy_ajp.c +++ b/modules/proxy/mod_proxy_ajp.c @@ -32,7 +32,7 @@ static int proxy_ajp_canon(request_rec *r, char *url) char *host, *path, sport[7]; char *search = NULL; const char *err; - apr_port_t port = AJP13_DEF_PORT; + apr_port_t port, def_port; /* ap_port_of_scheme() */ if (strncasecmp(url, "ajp:", 4) == 0) { @@ -48,6 +48,8 @@ static int proxy_ajp_canon(request_rec *r, char *url) * do syntactic check. * We break the URL into host, port, path, search */ + port = def_port = ap_proxy_port_of_scheme("ajp"); + err = ap_proxy_canon_netloc(r->pool, &url, NULL, NULL, &host, &port); if (err) { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00867) "error parsing URL %s: %s", @@ -71,7 +73,10 @@ static int proxy_ajp_canon(request_rec *r, char *url) if (path == NULL) return HTTP_BAD_REQUEST; - apr_snprintf(sport, sizeof(sport), ":%d", port); + if (port != def_port) + apr_snprintf(sport, sizeof(sport), ":%d", port); + else + sport[0] = '\0'; if (ap_strchr_c(host, ':')) { /* if literal IPv6 address */ diff --git a/modules/proxy/mod_proxy_fcgi.c b/modules/proxy/mod_proxy_fcgi.c index 56c9c37456..a718a203d8 100644 --- a/modules/proxy/mod_proxy_fcgi.c +++ b/modules/proxy/mod_proxy_fcgi.c @@ -30,7 +30,7 @@ static int proxy_fcgi_canon(request_rec *r, char *url) { char *host, sport[7]; const char *err, *path; - apr_port_t port = 8000; + apr_port_t port, def_port; if (strncasecmp(url, "fcgi:", 5) == 0) { url += 5; @@ -39,9 +39,10 @@ static int proxy_fcgi_canon(request_rec *r, char *url) return DECLINED; } + port = def_port = ap_proxy_port_of_scheme("fcgi"); + ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "canonicalising URL %s", url); - err = ap_proxy_canon_netloc(r->pool, &url, NULL, NULL, &host, &port); if (err) { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01059) @@ -49,7 +50,10 @@ static int proxy_fcgi_canon(request_rec *r, char *url) return HTTP_BAD_REQUEST; } - apr_snprintf(sport, sizeof(sport), ":%d", port); + if (port != def_port) + apr_snprintf(sport, sizeof(sport), ":%d", port); + else + sport[0] = '\0'; if (ap_strchr_c(host, ':')) { /* if literal IPv6 address */ @@ -752,7 +756,7 @@ static int proxy_fcgi_handler(request_rec *r, proxy_worker *worker, int status; char server_portstr[32]; conn_rec *origin = NULL; - proxy_conn_rec *backend = NULL; + proxy_conn_rec *backend; proxy_dir_conf *dconf = ap_get_module_config(r->per_dir_config, &proxy_module); @@ -765,10 +769,7 @@ static int proxy_fcgi_handler(request_rec *r, proxy_worker *worker, "url: %s proxyname: %s proxyport: %d", url, proxyname, proxyport); - if (strncasecmp(url, "fcgi:", 5) == 0) { - url += 5; - } - else { + if (strncasecmp(url, "fcgi:", 5) != 0) { ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01077) "declining URL %s", url); return DECLINED; } @@ -776,16 +777,14 @@ static int proxy_fcgi_handler(request_rec *r, proxy_worker *worker, ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01078) "serving URL %s", url); /* Create space for state information */ - if (! backend) { - status = ap_proxy_acquire_connection(FCGI_SCHEME, &backend, worker, - r->server); - if (status != OK) { - if (backend) { - backend->close = 1; - ap_proxy_release_connection(FCGI_SCHEME, backend, r->server); - } - return status; + status = ap_proxy_acquire_connection(FCGI_SCHEME, &backend, worker, + r->server); + if (status != OK) { + if (backend) { + backend->close = 1; + ap_proxy_release_connection(FCGI_SCHEME, backend, r->server); } + return status; } backend->is_ssl = 0; diff --git a/modules/proxy/mod_proxy_http.c b/modules/proxy/mod_proxy_http.c index f166720b2e..8f20378cbf 100644 --- a/modules/proxy/mod_proxy_http.c +++ b/modules/proxy/mod_proxy_http.c @@ -54,7 +54,7 @@ static int proxy_http_canon(request_rec *r, char *url) else { return DECLINED; } - def_port = apr_uri_port_of_scheme(scheme); + port = def_port = ap_proxy_port_of_scheme(scheme); ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "HTTP: canonicalising URL %s", url); @@ -62,7 +62,6 @@ static int proxy_http_canon(request_rec *r, char *url) /* do syntatic check. * We break the URL into host, port, path, search */ - port = def_port; err = ap_proxy_canon_netloc(r->pool, &url, NULL, NULL, &host, &port); if (err) { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01083) diff --git a/modules/proxy/proxy_util.c b/modules/proxy/proxy_util.c index 39d5caf432..bd9048ad07 100644 --- a/modules/proxy/proxy_util.c +++ b/modules/proxy/proxy_util.c @@ -21,6 +21,7 @@ #include "apr_version.h" #include "apr_hash.h" #include "proxy_util.h" +#include "ajp.h" #if APR_HAVE_UNISTD_H #include /* for getpid() */ @@ -2162,7 +2163,7 @@ ap_proxy_determine_connection(apr_pool_t *p, request_rec *r, NULL)); } if (!uri->port) { - uri->port = apr_uri_port_of_scheme(uri->scheme); + uri->port = ap_proxy_port_of_scheme(uri->scheme); } ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00944) @@ -3400,6 +3401,38 @@ PROXY_DECLARE(int) ap_proxy_pass_brigade(apr_bucket_alloc_t *bucket_alloc, return OK; } +/* Fill in unknown schemes from apr_uri_port_of_scheme() */ + +typedef struct proxy_schemes_t { + const char *name; + apr_port_t default_port; +} proxy_schemes_t ; + +static proxy_schemes_t pschemes[] = +{ + {"fcgi", 8000}, + {"ajp", AJP13_DEF_PORT}, + { NULL, 0xFFFF } /* unknown port */ +}; + +PROXY_DECLARE(apr_port_t) ap_proxy_port_of_scheme(const char *scheme) +{ + if (scheme) { + apr_port_t port; + if ((port = apr_uri_port_of_scheme(scheme)) != 0) { + return port; + } else { + proxy_schemes_t *pscheme; + for (pscheme = pschemes; pscheme->name != NULL; ++pscheme) { + if (strcasecmp(scheme, pscheme->name) == 0) { + return pscheme->default_port; + } + } + } + } + return 0; +} + void proxy_util_register_hooks(apr_pool_t *p) { APR_REGISTER_OPTIONAL_FN(ap_proxy_retry_worker);