diff -Naurp httpd-2.4.x.orig/docs/manual/mod/mod_proxy.xml httpd-2.4.x.new/docs/manual/mod/mod_proxy.xml --- httpd-2.4.x.orig/docs/manual/mod/mod_proxy.xml 2014-11-03 14:51:41.961619210 +0100 +++ httpd-2.4.x.new/docs/manual/mod/mod_proxy.xml 2014-11-03 15:52:33.083979540 +0100 @@ -1517,6 +1517,41 @@ will rewrite a cookie with backend path +ProxyPassReverseCookiePathMatch +Adjusts the Path string in Set-Cookie headers from a reverse- +proxied server using a regular expression +ProxyPassReverseCookiePathMatch regex +public-path [interpolate] +server configvirtual host +directory + + +

+This directive is equivalent to +ProxyPassReverseCookiePath, +but makes use of regular expressions +instead of simple prefix matching. In addition, public-path is +subject to parenthesized matches substitution, thus allowing a dynamic path +mapping. +

+

+As a special case, if public-path is set to !, the +cookie path is left unchanged: this can be used to disable matching by the +subsequent ProxyPassReverseCookie/ +ProxyPassReverseCookiePath directives. +

+

+In example, the following statement maps the path prefix (where +ProxyPassReverseCookie would have +replaced the full path), keeping the path trailer: +

+ + ProxyPassReverseCookiePathMatch ^/(.*)$ /foo/$1 + +
+
+ + ProxyBlock Words, hosts, or domains that are banned from being proxied @@ -1879,15 +1914,17 @@ header for proxied requests

This directive, together with the interpolate argument to ProxyPass, ProxyPassReverse, - ProxyPassReverseCookieDomain and - ProxyPassReverseCookiePath + ProxyPassReverseCookieDomain, + ProxyPassReverseCookiePath and + ProxyPassReverseCookiePathMatch enables reverse proxies to be dynamically configured using environment variables, which may be set by another module such as mod_rewrite. It affects the ProxyPass, ProxyPassReverse, - ProxyPassReverseCookieDomain, and - ProxyPassReverseCookiePath directives, + ProxyPassReverseCookieDomain, + ProxyPassReverseCookiePath and + ProxyPassReverseCookiePathMatch directives, and causes them to substitute the value of an environment variable varname for the string ${varname} in configuration directives (if the interpolate option is set).

diff -Naurp httpd-2.4.x.orig/docs/manual/urlmapping.xml httpd-2.4.x.new/docs/manual/urlmapping.xml --- httpd-2.4.x.orig/docs/manual/urlmapping.xml 2014-11-03 14:51:43.115629305 +0100 +++ httpd-2.4.x.new/docs/manual/urlmapping.xml 2014-11-03 14:58:25.791134780 +0100 @@ -58,6 +58,7 @@ ProxyPassReverse ProxyPassReverseCookieDomain ProxyPassReverseCookiePath +ProxyPassReverseCookiePathMatch Redirect RedirectMatch RewriteCond @@ -279,8 +280,9 @@ the server to fetch the appropriate docu directive rewrites redirects originating at internal.example.com so that they target the appropriate directory on the local server. Similarly, the -ProxyPassReverseCookieDomain -and ProxyPassReverseCookiePath +ProxyPassReverseCookieDomain, +ProxyPassReverseCookiePath +and ProxyPassReverseCookiePathMatch rewrite cookies set by the backend server.

It is important to note, however, that links inside the documents will not be rewritten. So any absolute diff -Naurp httpd-2.4.x.orig/modules/proxy/mod_proxy.c httpd-2.4.x.new/modules/proxy/mod_proxy.c --- httpd-2.4.x.orig/modules/proxy/mod_proxy.c 2014-11-03 14:51:46.213656406 +0100 +++ httpd-2.4.x.new/modules/proxy/mod_proxy.c 2014-11-03 14:52:54.436253123 +0100 @@ -1723,10 +1723,26 @@ static const char* cookie_path(cmd_parms new = apr_array_push(conf->cookie_paths); new->fake = f; new->real = r; + new->regex = NULL; new->flags = interp ? PROXYPASS_INTERPOLATE : 0; return NULL; } +static const char* cookie_path_regex(cmd_parms *cmd, void *dconf, const char *f, + const char *r, const char *interp) +{ + proxy_dir_conf *conf = dconf; + struct proxy_alias *new; + + new = apr_array_push(conf->cookie_paths); + new->fake = f; + new->real = r; + new->flags = interp ? PROXYPASS_INTERPOLATE : 0; + new->regex = ap_pregcomp(cmd->pool, f, AP_REG_EXTENDED); + if (new->regex == NULL) + return "Regular expression could not be compiled."; + return NULL; +} static const char* cookie_domain(cmd_parms *cmd, void *dconf, const char *f, const char *r, const char *interp) { @@ -2401,6 +2417,8 @@ static const command_rec proxy_cmds[] = "a virtual path and a URL for reverse proxy behaviour"), AP_INIT_TAKE23("ProxyPassReverseCookiePath", cookie_path, NULL, RSRC_CONF|ACCESS_CONF, "Path rewrite rule for proxying cookies"), + AP_INIT_TAKE23("ProxyPassReverseCookiePathMatch", cookie_path_regex, NULL, + RSRC_CONF|ACCESS_CONF, "Path rewrite rule for proxying cookies"), AP_INIT_TAKE23("ProxyPassReverseCookieDomain", cookie_domain, NULL, RSRC_CONF|ACCESS_CONF, "Domain rewrite rule for proxying cookies"), AP_INIT_ITERATE("ProxyBlock", set_proxy_exclude, NULL, RSRC_CONF, diff -Naurp httpd-2.4.x.orig/modules/proxy/proxy_util.c httpd-2.4.x.new/modules/proxy/proxy_util.c --- httpd-2.4.x.orig/modules/proxy/proxy_util.c 2014-11-03 14:51:46.371657788 +0100 +++ httpd-2.4.x.new/modules/proxy/proxy_util.c 2014-11-03 14:52:54.437253147 +0100 @@ -971,6 +971,7 @@ PROXY_DECLARE(const char *) ap_proxy_coo const char *pathe = NULL; const char *domaine = NULL; apr_size_t l1, l2, poffs = 0, doffs = 0; + ap_regmatch_t regm[AP_MAX_REG_MATCH]; int i; int ddiff = 0; int pdiff = 0; @@ -997,11 +998,24 @@ PROXY_DECLARE(const char *) ap_proxy_coo ent = (struct proxy_alias *)conf->cookie_paths->elts; } for (i = 0; i < conf->cookie_paths->nelts; i++) { - l2 = strlen(ent[i].fake); - if (l1 >= l2 && strncmp(ent[i].fake, pathp, l2) == 0) { - newpath = ent[i].real; - pdiff = strlen(newpath) - l1; - break; + if (ent[i].regex) { + if (!ap_regexec_len(ent[i].regex, pathp, l1, AP_MAX_REG_MATCH, + regm, 0)) { + if (ent[i].real[0] == '!' && ent[i].real[1] == '\0') + break; + newpath = ap_pregsub(r->pool, ent[i].real, pathp, + AP_MAX_REG_MATCH, regm); + pdiff = strlen(newpath) - l1; + break; + } + } + else { + l2 = strlen(ent[i].fake); + if (l1 >= l2 && strncmp(ent[i].fake, pathp, l2) == 0) { + newpath = ent[i].real; + pdiff = strlen(newpath) - l1; + break; + } } } }