]> granicus.if.org Git - apache/commitdiff
Merge r1725149, r1726233, r1729374, r1729374 from trunk:
authorJim Jagielski <jim@apache.org>
Thu, 11 Feb 2016 19:06:16 +0000 (19:06 +0000)
committerJim Jagielski <jim@apache.org>
Thu, 11 Feb 2016 19:06:16 +0000 (19:06 +0000)
allow expressions to be used in SetHandler. Opt-in with expr= prefix.

from feedback, assume all parameters to SetHandler are expressions.

I couldnt come up with a plausible handler name that was an
invalid expression.

1726233 temporarily broke UDS r->handler case sensitivity

1726233 temporarily broke UDS r->handler case sensitivity

Submitted by: covener
Reviewed/backported by: jim

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1729876 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
STATUS
docs/manual/mod/core.xml
include/ap_mmn.h
include/http_core.h
server/core.c

diff --git a/CHANGES b/CHANGES
index 3a0193825abaa2a5e93a7fe09ae8ad2c9c52e5a8..a69519976d4ebc879ad50e0d2d7f99cc8fa84912 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,8 @@
                                                          -*- coding: utf-8 -*-
 
 Changes with Apache 2.4.19
+  *) core: Add expression support to SetHandler.
+     [Eric Covener]
 
   *) core: Prevent a server crash in case of an invalid CONNECT request with
      a custom error page for status code 400 that uses server side includes.
diff --git a/STATUS b/STATUS
index 3f28ae73a6f49802a294df0b868cf989f76e005e..910b37b1338dd1ce73741d2dcb3bda92ce77d5d4 100644 (file)
--- a/STATUS
+++ b/STATUS
@@ -112,16 +112,6 @@ RELEASE SHOWSTOPPERS:
 PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
   [ start all new proposals below, under PATCHES PROPOSED. ]
 
-  *) core: Add expression support to SetHandler (someone wanted this in
-     a well-articulated serverfault post).
-     trunk patch:  http://svn.apache.org/r1725149
-                   http://svn.apache.org/r1725151
-                   http://svn.apache.org/r1726233
-                   http://svn.apache.org/r1729374
-     2.4.x patch: MMN/changes only: http://people.apache.org/~covener/patches/2.4.x-sethandler-expr-2.diff
-                                    + http://svn.apache.org/r1729374 
-     +1: covener, jim, ylavic
-
   *) core: introducing new hook "pre_close_connection" to give protocols other
      than http/1.1 a chance to send one last frame before close.
      Requires MMN bump
index 7089893f09469ff80226ff56be01b26f50d8a540..3b8b6c9305389e316809fcc8b718fcae1ad386d2 100644 (file)
@@ -4173,11 +4173,12 @@ header</description>
 <name>SetHandler</name>
 <description>Forces all matching files to be processed by a
 handler</description>
-<syntax>SetHandler <var>handler-name</var>|None</syntax>
+<syntax>SetHandler <var>handler-name</var>|none|<var>expression</var></syntax>
 <contextlist><context>server config</context><context>virtual host</context>
 <context>directory</context><context>.htaccess</context>
 </contextlist>
 <override>FileInfo</override>
+<compatibility>2.4.19 and later</compatibility>
 
 <usage>
     <p>When placed into an <code>.htaccess</code> file or a
@@ -4212,6 +4213,15 @@ handler</description>
 &lt;/FilesMatch&gt;
     </highlight>
 
+    <p>String-valued expressions can be used to reference per-request 
+    variables, including backreferences to named regular expressions:</p>
+
+    <highlight language="config">
+&lt;LocationMatch ^/app/(?&lt;sub&gt;[^/]+)/&gt;
+     SetHandler "proxy:unix:/var/run/app_%{env:MATCH_sub}.sock|fcgi://localhost:8080"
+&lt;/FilesMatch&gt;
+    </highlight>
+
     <p>You can override an earlier defined <directive>SetHandler</directive>
     directive by using the value <code>None</code>.</p>
 
index 3233ef8027de71c6ac3463fbe05de185e669723e..aa6dfd080d085755df5e553c4e1c1cb089af8ad2 100644 (file)
  *                          ap_get_protocol(). Add HTTP_MISDIRECTED_REQUEST.
  *                          Added ap_parse_token_list_strict() to httpd.h
  * 20120211.52 (2.4.17-dev) Add master conn_rec* member in conn_rec.
+ * 20120211.53 (2.4.17-dev) Add epxr_hander to core_dir_config.
  */
 
 #define MODULE_MAGIC_COOKIE 0x41503234UL /* "AP24" */
 #ifndef MODULE_MAGIC_NUMBER_MAJOR
 #define MODULE_MAGIC_NUMBER_MAJOR 20120211
 #endif
-#define MODULE_MAGIC_NUMBER_MINOR 52                   /* 0...n */
+#define MODULE_MAGIC_NUMBER_MINOR 53                   /* 0...n */
 
 /**
  * Determine if the server's current MODULE_MAGIC_NUMBER is at least a
index 85354552c11b65cd35ee55332ddce593be4b1c39..97cb864072cb559f4b0a0866250070f252e73d52 100644 (file)
@@ -565,7 +565,7 @@ typedef struct {
     ap_regex_t *r;
 
     const char *mime_type;       /* forced with ForceType  */
-    const char *handler;         /* forced with SetHandler */
+    const char *handler;         /* forced by something other than SetHandler */
     const char *output_filters;  /* forced with SetOutputFilters */
     const char *input_filters;   /* forced with SetInputFilters */
     int accept_path_info;        /* forced with AcceptPathInfo */
@@ -642,7 +642,7 @@ typedef struct {
      */
     unsigned int cgi_pass_auth : 2;
     unsigned int qualify_redirect_url :2;
-
+    ap_expr_info_t  *expr_handler;         /* forced with SetHandler */
 } core_dir_config;
 
 /* macro to implement off by default behaviour */
index 9ee2638f50aa4fceb55cc941a01c76e3fb73c915..4dd8200d3668b1870836cffb0cedbd446ea74ea5 100644 (file)
@@ -349,6 +349,9 @@ static void *merge_core_dir_configs(apr_pool_t *a, void *basev, void *newv)
     if (new->handler) {
         conf->handler = new->handler;
     }
+    if (new->expr_handler) {
+        conf->expr_handler = new->expr_handler;
+    }
 
     if (new->output_filters) {
         conf->output_filters = new->output_filters;
@@ -1890,16 +1893,14 @@ static const char *set_sethandler(cmd_parms *cmd,
                                      const char *arg_)
 {
     core_dir_config *dirconf = d_;
-
-    if (arg_ == ap_strstr_c(arg_, "proxy:unix")) { 
-        dirconf->handler = arg_;
-    }
-    else { 
-        char *arg = apr_pstrdup(cmd->pool,arg_);
-        ap_str_tolower(arg);
-        dirconf->handler = arg;
+    const char *err;
+    dirconf->expr_handler = ap_expr_parse_cmd(cmd, arg_,
+                                          AP_EXPR_FLAG_STRING_RESULT,
+                                          &err, NULL);
+    if (err) {
+        return apr_pstrcat(cmd->pool,
+                "Can't parse expression : ", err, NULL);
     }
-
     return NULL;
 }
 
@@ -4360,8 +4361,30 @@ static int core_override_type(request_rec *r)
     if (conf->mime_type && strcmp(conf->mime_type, "none"))
         ap_set_content_type(r, (char*) conf->mime_type);
 
-    if (conf->handler && strcmp(conf->handler, "none"))
+    if (conf->expr_handler) { 
+        const char *err;
+        const char *val;
+        val = ap_expr_str_exec(r, conf->expr_handler, &err);
+        if (err) {
+            ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO()
+                          "Can't evaluate handler expression: %s", err);
+            return HTTP_INTERNAL_SERVER_ERROR;
+        }
+        if (strcmp(val, "none")) { 
+            if (val != ap_strstr_c(val, "proxy:unix")) { 
+                /* Retained for compatibility --  but not for UDS */
+                char *tmp = apr_pstrdup(r->pool, val);
+                ap_str_tolower(tmp);
+                r->handler = tmp;
+            }
+            else { 
+                r->handler = val;
+            }
+        }
+    }
+    else if (conf->handler && strcmp(conf->handler, "none")) { 
         r->handler = conf->handler;
+    }
 
     /* Deal with the poor soul who is trying to force path_info to be
      * accepted within the core_handler, where they will let the subreq