You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by yl...@apache.org on 2020/06/24 10:16:06 UTC

svn commit: r1879145 - in /httpd/httpd/trunk: include/ap_mmn.h modules/proxy/mod_proxy.c modules/proxy/mod_proxy.h

Author: ylavic
Date: Wed Jun 24 10:16:06 2020
New Revision: 1879145

URL: http://svn.apache.org/viewvc?rev=1879145&view=rev
Log:
Follow up to r1879080: replace ProxyUseOriginalURI by mapping=encoded.

Instead of having a separate ProxyUseOriginalURI directive to control pre_ vs
normal translate stage, let's handle this at each ProxyPass level, with the
mapping= parameter.

At pre_translate stage mod_proxy will handle the "encoded" mapping only, and
at translate stage only the others (unless a worker was already elected at
the first stage).

Note that since mapping=servlet needs to happen encoded too, it's defined like:
    #define PROXYPASS_MAP_ENCODED 0x08
    #define PROXYPASS_MAP_SERVLET 0x18 /* + MAP_ENCODED */
so uch that proxy_trans does the right thing.

Follow up to r1879080: replace ProxyUseOriginalURI by mapping=encoded.

Instead of having a separate ProxyUseOriginalURI directive to control pre_ vs
normal translate stage, let's handle this at each ProxyPass level, with the
mapping= parameter.

At pre_translate stage mod_proxy will handle the "encoded" mapping only, and
at translate stage only the others (unless a worker was already elected at
the first stage).

Note that since mapping=servlet needs to happen encoded too, it's defined like:
    #define PROXYPASS_MAP_ENCODED 0x08
    #define PROXYPASS_MAP_SERVLET 0x18 /* + MAP_ENCODED */
so that proxy_trans does the right thing.

This allows for simpler and consistent mapping configuration, where the
translate stage depends only on the mapping= parameter.

To implement a fast path (do nothing) when no encoded mapping is configured
at pre_trans stage, or all mappings are encoded at translate stage, two bits
are added to proxy_server_conf (map_encoded_one:1, map_encoded_all:1) and
updated at load time. Thus MINOR is bumped too.

Modified:
    httpd/httpd/trunk/include/ap_mmn.h
    httpd/httpd/trunk/modules/proxy/mod_proxy.c
    httpd/httpd/trunk/modules/proxy/mod_proxy.h

Modified: httpd/httpd/trunk/include/ap_mmn.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/include/ap_mmn.h?rev=1879145&r1=1879144&r2=1879145&view=diff
==============================================================================
--- httpd/httpd/trunk/include/ap_mmn.h (original)
+++ httpd/httpd/trunk/include/ap_mmn.h Wed Jun 24 10:16:06 2020
@@ -634,6 +634,8 @@
  * 20200420.3 (2.5.1-dev)  Add ap_parse_strict_length()
  * 20200420.4 (2.5.1-dev)  Add ap_normalize_path()
  * 20200420.5 (2.5.1-dev)  Add pre_translate_name hook
+ * 20200420.6 (2.5.1-dev)  Add map_encoded_one and map_encoded_all bits to
+ *                         proxy_server_conf
  */
 
 #define MODULE_MAGIC_COOKIE 0x41503235UL /* "AP25" */
@@ -641,7 +643,7 @@
 #ifndef MODULE_MAGIC_NUMBER_MAJOR
 #define MODULE_MAGIC_NUMBER_MAJOR 20200420
 #endif
-#define MODULE_MAGIC_NUMBER_MINOR 5            /* 0...n */
+#define MODULE_MAGIC_NUMBER_MINOR 6            /* 0...n */
 
 /**
  * Determine if the server's current MODULE_MAGIC_NUMBER is at least a

Modified: httpd/httpd/trunk/modules/proxy/mod_proxy.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/proxy/mod_proxy.c?rev=1879145&r1=1879144&r2=1879145&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/proxy/mod_proxy.c (original)
+++ httpd/httpd/trunk/modules/proxy/mod_proxy.c Wed Jun 24 10:16:06 2020
@@ -932,12 +932,7 @@ PROXY_DECLARE(int) ap_proxy_trans_match(
         }
     }
     else {
-        /* Ignore servlet mapping if r->uri was decoded already, or we
-         * might consider for instance that an original %3B is a delimiter
-         * for path parameters (which is not).
-         */
-        if (dconf->use_original_uri == 1
-                && (ent->flags & PROXYPASS_MAPPING_SERVLET)) {
+        if ((ent->flags & PROXYPASS_MAP_SERVLET) == PROXYPASS_MAP_SERVLET) {
             nocanon = 0; /* ignored since servlet's normalization applies */
             len = alias_match_servlet(r->pool, r->uri, fake);
         }
@@ -1000,7 +995,7 @@ PROXY_DECLARE(int) ap_proxy_trans_match(
 
 static int proxy_trans(request_rec *r, int pre_trans)
 {
-    int i;
+    int i, enc;
     struct proxy_alias *ent;
     proxy_dir_conf *dconf;
     proxy_server_conf *conf;
@@ -1019,11 +1014,17 @@ static int proxy_trans(request_rec *r, i
      */
 
     dconf = ap_get_module_config(r->per_dir_config, &proxy_module);
+    conf = (proxy_server_conf *) ap_get_module_config(r->server->module_config,
+                                                      &proxy_module);
 
-    /* Do the work from the hook corresponding to the ProxyUseOriginalURI
-     * configuration (off/default: translate hook, on: pre_translate hook).
+    /* Always and only do PROXY_MAP_ENCODED mapping in pre_trans, when
+     * r->uri is still encoded, or we might consider for instance that
+     * a decoded sub-delim is now a delimiter (e.g. "%3B" => ';' for
+     * path parameters), which it's not.
      */
-    if (pre_trans ^ (dconf->use_original_uri == 1)) {
+    if ((pre_trans && !conf->map_encoded_one)
+            || (!pre_trans && conf->map_encoded_all)) {
+        /* Fast path, nothing at this stage */
         return DECLINED;
     }
 
@@ -1038,20 +1039,21 @@ static int proxy_trans(request_rec *r, i
 
     /* short way - this location is reverse proxied? */
     if (dconf->alias) {
-        int rv = ap_proxy_trans_match(r, dconf->alias, dconf);
-        if (DONE != rv) {
-            return rv;
+        enc = (dconf->alias->flags & PROXYPASS_MAP_ENCODED) != 0;
+        if (!(pre_trans ^ enc)) {
+            int rv = ap_proxy_trans_match(r, dconf->alias, dconf);
+            if (DONE != rv) {
+                return rv;
+            }
         }
     }
 
-    conf = (proxy_server_conf *) ap_get_module_config(r->server->module_config,
-                                                      &proxy_module);
-
     /* long way - walk the list of aliases, find a match */
-    if (conf->aliases->nelts) {
-        ent = (struct proxy_alias *) conf->aliases->elts;
-        for (i = 0; i < conf->aliases->nelts; i++) {
-            int rv = ap_proxy_trans_match(r, &ent[i], dconf);
+    for (i = 0; i < conf->aliases->nelts; i++) {
+        ent = &((struct proxy_alias *)conf->aliases->elts)[i];
+        enc = (ent->flags & PROXYPASS_MAP_ENCODED) != 0;
+        if (!(pre_trans ^ enc)) {
+            int rv = ap_proxy_trans_match(r, ent, dconf);
             if (DONE != rv) {
                 return rv;
             }
@@ -1065,6 +1067,7 @@ static int proxy_pre_translate_name(requ
 {
     return proxy_trans(r, 1);
 }
+
 static int proxy_translate_name(request_rec *r)
 {
     return proxy_trans(r, 0);
@@ -1590,6 +1593,8 @@ static void * create_proxy_config(apr_po
     ps->forward = NULL;
     ps->reverse = NULL;
     ps->domain = NULL;
+    ps->map_encoded_one = 0;
+    ps->map_encoded_all = 1;
     ps->id = apr_psprintf(p, "p%x", 1); /* simply for storage size */
     ps->viaopt = via_off; /* initially backward compatible with 1.3.1 */
     ps->viaopt_set = 0; /* 0 means default */
@@ -1747,6 +1752,9 @@ static void * merge_proxy_config(apr_poo
     ps->forward = overrides->forward ? overrides->forward : base->forward;
     ps->reverse = overrides->reverse ? overrides->reverse : base->reverse;
 
+    ps->map_encoded_one = overrides->map_encoded_one || base->map_encoded_one;
+    ps->map_encoded_all = overrides->map_encoded_all && base->map_encoded_all;
+
     ps->domain = (overrides->domain == NULL) ? base->domain : overrides->domain;
     ps->id = (overrides->id == NULL) ? base->id : overrides->id;
     ps->viaopt = (overrides->viaopt_set == 0) ? base->viaopt : overrides->viaopt;
@@ -1814,7 +1822,6 @@ static void *create_proxy_dir_config(apr
     new->add_forwarded_headers_set = 0;
     new->forward_100_continue = 1;
     new->forward_100_continue_set = 0;
-    new->use_original_uri = -1; /* unset (off by default) */
 
     return (void *) new;
 }
@@ -1872,10 +1879,6 @@ static void *merge_proxy_dir_config(apr_
                                              : add->forward_100_continue;
     new->forward_100_continue_set = add->forward_100_continue_set
                                     || base->forward_100_continue_set;
-    
-    new->use_original_uri = (add->use_original_uri == -1)
-                                ? base->use_original_uri
-                                : add->use_original_uri;
 
     return new;
 }
@@ -2032,9 +2035,6 @@ static const char *
         else if (!strcasecmp(word,"noquery")) {
             flags |= PROXYPASS_NOQUERY;
         }
-        else if (!strcasecmp(word,"mapping=servlet")) {
-            flags |= PROXYPASS_MAPPING_SERVLET;
-        }
         else {
             char *val = strchr(word, '=');
             if (!val) {
@@ -2053,11 +2053,31 @@ static const char *
                            "in the form 'key=value'.";
                 }
             }
-            else
+            else {
                 *val++ = '\0';
-            apr_table_setn(params, word, val);
+            }
+            if (!strcasecmp(word, "mapping")) {
+                if (!strcasecmp(val, "encoded")) {
+                    flags |= PROXYPASS_MAP_ENCODED;
+                }
+                else if (!strcasecmp(val, "servlet")) {
+                    flags |= PROXYPASS_MAP_SERVLET;
+                }
+                else {
+                    return "unknown mapping";
+                }
+            }
+            else {
+                apr_table_setn(params, word, val);
+            }
         }
-    };
+    }
+    if (flags & PROXYPASS_MAP_ENCODED) {
+        conf->map_encoded_one = 1;
+    }
+    else {
+        conf->map_encoded_all = 0;
+    }
 
     if (r == NULL) {
         return "ProxyPass|ProxyPassMatch needs a path when not defined in a location";
@@ -3028,9 +3048,6 @@ static const command_rec proxy_cmds[] =
     AP_INIT_FLAG("Proxy100Continue", forward_100_continue, NULL, RSRC_CONF|ACCESS_CONF,
      "on if 100-Continue should be forwarded to the origin server, off if the "
      "proxy should handle it by itself"),
-    AP_INIT_FLAG("ProxyUseOriginalURI", ap_set_flag_slot_char,
-     (void*)APR_OFFSETOF(proxy_dir_conf, use_original_uri), RSRC_CONF|ACCESS_CONF,
-     "Whether to use the original/encoded URI-path for mapping"),
     {NULL}
 };
 

Modified: httpd/httpd/trunk/modules/proxy/mod_proxy.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/proxy/mod_proxy.h?rev=1879145&r1=1879144&r2=1879145&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/proxy/mod_proxy.h (original)
+++ httpd/httpd/trunk/modules/proxy/mod_proxy.h Wed Jun 24 10:16:06 2020
@@ -123,7 +123,8 @@ struct proxy_remote {
 #define PROXYPASS_NOCANON 0x01
 #define PROXYPASS_INTERPOLATE 0x02
 #define PROXYPASS_NOQUERY 0x04
-#define PROXYPASS_MAPPING_SERVLET 0x08
+#define PROXYPASS_MAP_ENCODED 0x08
+#define PROXYPASS_MAP_SERVLET 0x18 /* + MAP_ENCODED */
 struct proxy_alias {
     const char  *real;
     const char  *fake;
@@ -200,6 +201,8 @@ typedef struct {
     unsigned int inherit_set:1;
     unsigned int ppinherit:1;
     unsigned int ppinherit_set:1;
+    unsigned int map_encoded_one:1;
+    unsigned int map_encoded_all:1;
 } proxy_server_conf;
 
 typedef struct {
@@ -244,9 +247,6 @@ typedef struct {
     unsigned int forward_100_continue_set:1;
 
     apr_array_header_t *error_override_codes;
-
-    /** Whether to use original/encoded URI-path or not (default) */
-    signed char use_original_uri;
 } proxy_dir_conf;
 
 /* if we interpolate env vars per-request, we'll need a per-request



Re: svn commit: r1879145 - in /httpd/httpd/trunk: include/ap_mmn.h modules/proxy/mod_proxy.c modules/proxy/mod_proxy.h

Posted by Yann Ylavic <yl...@gmail.com>.
Hi Jean-Frédéric,

On Tue, Jun 1, 2021 at 4:50 PM jean-frederic clere <jf...@gmail.com> wrote:
>
> On 24/06/2020 12:16, ylavic@apache.org wrote:
> > Author: ylavic
> > Date: Wed Jun 24 10:16:06 2020
> > New Revision: 1879145
> >
> > URL: http://svn.apache.org/viewvc?rev=1879145&view=rev
> > Log:
> > Follow up to r1879080: replace ProxyUseOriginalURI by mapping=encoded.
> >
> > Instead of having a separate ProxyUseOriginalURI directive to control pre_ vs
> > normal translate stage, let's handle this at each ProxyPass level, with the
> > mapping= parameter.
>
> Any plans to document the feature? If not, I will prepare tests and docs ;-)

I forgot about this one, thanks for the reminder.
I have no cycles these following days, feel free to beat me at it if
you want/can, otherwise I'll have a look when time permits ;)

Regards;
Yann.

Re: svn commit: r1879145 - in /httpd/httpd/trunk: include/ap_mmn.h modules/proxy/mod_proxy.c modules/proxy/mod_proxy.h

Posted by jean-frederic clere <jf...@gmail.com>.
On 24/06/2020 12:16, ylavic@apache.org wrote:
> Author: ylavic
> Date: Wed Jun 24 10:16:06 2020
> New Revision: 1879145
> 
> URL: http://svn.apache.org/viewvc?rev=1879145&view=rev
> Log:
> Follow up to r1879080: replace ProxyUseOriginalURI by mapping=encoded.
> 
> Instead of having a separate ProxyUseOriginalURI directive to control pre_ vs
> normal translate stage, let's handle this at each ProxyPass level, with the
> mapping= parameter.

Any plans to document the feature? If not, I will prepare tests and docs ;-)

Cheers

Jean-Frederic