ASF Bugzilla – Attachment 32183 Details for
Bug 54306
add regexp versions of ProxyPassReverse, ProxyPassReverseCookieDomain and ProxyPassReverseCookiePath
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
New directive ProxyPassReverseCookiePathMatch
httpd-2.4.x-ProxyPassReverseCookiePathMatch.patch (text/plain), 8.21 KB, created by
pm
on 2014-11-03 15:32:54 UTC
(
hide
)
Description:
New directive ProxyPassReverseCookiePathMatch
Filename:
MIME Type:
Creator:
pm
Created:
2014-11-03 15:32:54 UTC
Size:
8.21 KB
patch
obsolete
>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 > </directivesynopsis> > > <directivesynopsis> >+<name>ProxyPassReverseCookiePathMatch</name> >+<description>Adjusts the Path string in Set-Cookie headers from a reverse- >+proxied server using a regular expression</description> >+<syntax>ProxyPassReverseCookiePathMatch <var>regex</var> >+<var>public-path</var> [<var>interpolate</var>]</syntax> >+<contextlist><context>server config</context><context>virtual host</context> >+<context>directory</context> >+</contextlist> >+<usage> >+<p> >+This directive is equivalent to >+<directive module="mod_proxy">ProxyPassReverseCookiePath</directive>, >+but makes use of <glossary ref="regex">regular expressions</glossary> >+instead of simple prefix matching. In addition, <var>public-path</var> is >+subject to parenthesized matches substitution, thus allowing a dynamic path >+mapping. >+</p> >+<p> >+As a special case, if <var>public-path</var> is set to <code>!</code>, the >+cookie path is left unchanged: this can be used to disable matching by the >+subsequent <directive module="mod_proxy">ProxyPassReverseCookie</directive>/ >+<directive module="mod_proxy">ProxyPassReverseCookiePath</directive> directives. >+</p> >+<p> >+In example, the following statement maps the path prefix (where >+<directive module="mod_proxy">ProxyPassReverseCookie</directive> would have >+replaced the full path), keeping the path trailer: >+</p> >+ <highlight language="config"> >+ ProxyPassReverseCookiePathMatch ^/(.*)$ /foo/$1 >+ </highlight> >+</usage> >+</directivesynopsis> >+ >+<directivesynopsis> > <name>ProxyBlock</name> > <description>Words, hosts, or domains that are banned from being > proxied</description> >@@ -1879,15 +1914,17 @@ header for proxied requests</description > <usage> > <p>This directive, together with the <var>interpolate</var> argument to > <directive>ProxyPass</directive>, <directive>ProxyPassReverse</directive>, >- <directive>ProxyPassReverseCookieDomain</directive> and >- <directive>ProxyPassReverseCookiePath</directive> >+ <directive>ProxyPassReverseCookieDomain</directive>, >+ <directive>ProxyPassReverseCookiePath</directive> and >+ <directive>ProxyPassReverseCookiePathMatch</directive> > enables reverse proxies to be dynamically > configured using environment variables, which may be set by > another module such as <module>mod_rewrite</module>. > It affects the <directive>ProxyPass</directive>, > <directive>ProxyPassReverse</directive>, >- <directive>ProxyPassReverseCookieDomain</directive>, and >- <directive>ProxyPassReverseCookiePath</directive> directives, >+ <directive>ProxyPassReverseCookieDomain</directive>, >+ <directive>ProxyPassReverseCookiePath</directive> and >+ <directive>ProxyPassReverseCookiePathMatch</directive> directives, > and causes them to substitute the value of an environment > variable <code>varname</code> for the string <code>${varname}</code> > in configuration directives (if the <var>interpolate</var> option is set).</p> >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 @@ > <directive module="mod_proxy">ProxyPassReverse</directive> > <directive module="mod_proxy">ProxyPassReverseCookieDomain</directive> > <directive module="mod_proxy">ProxyPassReverseCookiePath</directive> >+<directive module="mod_proxy">ProxyPassReverseCookiePathMatch</directive> > <directive module="mod_alias">Redirect</directive> > <directive module="mod_alias">RedirectMatch</directive> > <directive module="mod_rewrite">RewriteCond</directive> >@@ -279,8 +280,9 @@ the server to fetch the appropriate docu > directive rewrites redirects originating at > <code>internal.example.com</code> so that they target the appropriate > directory on the local server. Similarly, the >-<directive module="mod_proxy">ProxyPassReverseCookieDomain</directive> >-and <directive module="mod_proxy">ProxyPassReverseCookiePath</directive> >+<directive module="mod_proxy">ProxyPassReverseCookieDomain</directive>, >+<directive module="mod_proxy">ProxyPassReverseCookiePath</directive> >+and <directive module="mod_proxy">ProxyPassReverseCookiePathMatch</directive> > rewrite cookies set by the backend server.</p> > <p>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; >+ } > } > } > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 54306
: 32183