Skip to content

Commit 6221c69

Browse files
author
jim
committed
Allow for "magic" scheme "auto" which makes the scheme of
the backend worker match whatever the scheme of the incoming request was... For example: ProxyPass / auto://foo.example.com/ If the incoming request is http:.../lala then the resultant will be http://foo.example.com/lala If it's wws:.../lolo then we'd send wws://foo.example.com/lolo git-svn-id: http://svn.apache.org/repos/asf/httpd/httpd/trunk@1602523 13f79535-47bb-0310-9956-ffa450edef68
1 parent 643e539 commit 6221c69

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

modules/proxy/mod_proxy.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,11 @@ static int proxy_handler(request_rec *r)
10451045
}
10461046

10471047
scheme = apr_pstrndup(r->pool, uri, p - uri);
1048+
1049+
if (strcmp(scheme, "auto") == 0) {
1050+
apr_table_set(r->notes, "auto", uri);
1051+
uri = apr_pstrcat(r->pool, ap_http_scheme(r), p, NULL);
1052+
}
10481053
/* Check URI's destination host against NoProxy hosts */
10491054
/* Bypass ProxyRemote server lookup if configured as NoProxy */
10501055
for (direct_connect = i = 0; i < conf->dirconn->nelts &&
@@ -1151,8 +1156,8 @@ static int proxy_handler(request_rec *r)
11511156

11521157
/* handle the scheme */
11531158
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01143)
1154-
"Running scheme %s handler (attempt %d)",
1155-
scheme, attempts);
1159+
"Running scheme %s handler for %s (attempt %d)",
1160+
scheme, url, attempts);
11561161
AP_PROXY_RUN(r, worker, conf, url, attempts);
11571162
access_status = proxy_run_scheme_handler(r, worker, conf,
11581163
url, NULL, 0);
@@ -1479,15 +1484,15 @@ static const char *
14791484

14801485
static char *de_socketfy(apr_pool_t *p, char *url)
14811486
{
1482-
char *ptr;
1487+
char *ptr, *ret = url;
14831488
/*
14841489
* We could be passed a URL during the config stage that contains
14851490
* the UDS path... ignore it
14861491
*/
14871492
if (!strncasecmp(url, "unix:", 5) &&
14881493
((ptr = ap_strchr(url, '|')) != NULL)) {
14891494
/* move past the 'unix:...|' UDS path info */
1490-
char *ret, *c;
1495+
char *c;
14911496

14921497
ret = ptr + 1;
14931498
/* special case: "unix:....|scheme:" is OK, expand
@@ -1498,13 +1503,10 @@ static char *de_socketfy(apr_pool_t *p, char *url)
14981503
return NULL;
14991504
}
15001505
if (c[1] == '\0') {
1501-
return apr_pstrcat(p, ret, "//localhost", NULL);
1502-
}
1503-
else {
1504-
return ret;
1506+
ret = apr_pstrcat(p, ret, "//localhost", NULL);
15051507
}
15061508
}
1507-
return url;
1509+
return ret;
15081510
}
15091511

15101512
static const char *

modules/proxy/proxy_util.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1907,7 +1907,11 @@ PROXY_DECLARE(int) ap_proxy_pre_request(proxy_worker **worker,
19071907

19081908
access_status = proxy_run_pre_request(worker, balancer, r, conf, url);
19091909
if (access_status == DECLINED && *balancer == NULL) {
1910-
*worker = ap_proxy_get_worker(r->pool, NULL, conf, *url);
1910+
const char *murl;
1911+
if ((murl = apr_table_get(r->notes, "auto")) == NULL) {
1912+
murl = *url;
1913+
}
1914+
*worker = ap_proxy_get_worker(r->pool, NULL, conf, murl);
19111915
if (*worker) {
19121916
ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, r,
19131917
"%s: found worker %s for %s",

0 commit comments

Comments
 (0)