From: Eric Covener Date: Sun, 17 Jan 2016 23:40:09 +0000 (+0000) Subject: allow expressions to be used in SetHandler. Opt-in with expr= prefix. X-Git-Tag: 2.5.0-alpha~2404 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e89938830a456da686fdb035918e087cf8344b5a;p=apache allow expressions to be used in SetHandler. Opt-in with expr= prefix. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1725149 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index 33666a4be5..b13c091ebc 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,9 @@ -*- coding: utf-8 -*- Changes with Apache 2.5.0 + *) core: Add expression support to SetHandler. + [Eric Covener] + *) mod_proxy_fcgi: Suppress HTTP error 503 and message 01075, "Error dispatching request", when the cause appears to be due to the client closing the connection. diff --git a/docs/manual/mod/core.xml b/docs/manual/mod/core.xml index 682792083c..1035178ce2 100644 --- a/docs/manual/mod/core.xml +++ b/docs/manual/mod/core.xml @@ -4318,11 +4318,12 @@ header SetHandler Forces all matching files to be processed by a handler -SetHandler handler-name|None +SetHandler handler-name|None|expr=expression server configvirtual host directory.htaccess FileInfo +2.5 and later

When placed into an .htaccess file or a @@ -4359,6 +4360,15 @@ SetHandler imap-file </FilesMatch> +

String-valued expressions can be used to reference per-request + variables, including backreferences to named regular expressions:

+ + +<LocationMatch ^/app/(?<sub>[^/]+)/> + SetHandler "expr=proxy:unix:/var/run/app_%{env:MATCH_sub}.sock|fcgi://localhost:8080" +</FilesMatch> + +

You can override an earlier defined SetHandler directive by using the value None.

diff --git a/include/ap_mmn.h b/include/ap_mmn.h index 53e2f1e1b2..6930e26926 100644 --- a/include/ap_mmn.h +++ b/include/ap_mmn.h @@ -497,6 +497,7 @@ * 20150222.6 (2.5.0-dev) Add async_filter to conn_rec. * 20150222.7 (2.5.0-dev) Add ap_casecmpstr[n](); * 20150222.8 (2.5.0-dev) Add ap_getword_conf2[_nc](); + * 20150222.9 (2.5.0-dev) Add epxr_hander to core_dir_config. */ #define MODULE_MAGIC_COOKIE 0x41503235UL /* "AP25" */ diff --git a/include/http_core.h b/include/http_core.h index 3ecd5f119f..eaff248575 100644 --- a/include/http_core.h +++ b/include/http_core.h @@ -646,7 +646,7 @@ typedef struct { apr_hash_t *response_code_exprs; unsigned int qualify_redirect_url :2; - + ap_expr_info_t *expr_handler; /* forced with SetHandler expr= */ } core_dir_config; /* macro to implement off by default behaviour */ diff --git a/server/core.c b/server/core.c index c9150b443d..1a464c1322 100644 --- a/server/core.c +++ b/server/core.c @@ -356,6 +356,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; @@ -1967,7 +1970,18 @@ static const char *set_sethandler(cmd_parms *cmd, { core_dir_config *dirconf = d_; - if (arg_ == ap_strstr_c(arg_, "proxy:unix")) { + if (!strncmp(arg_, "expr=", 5)) { + const char *err; + dirconf->expr_handler = ap_expr_parse_cmd(cmd, arg_+5, + AP_EXPR_FLAG_STRING_RESULT, + &err, NULL); + if (err) { + return apr_pstrcat(cmd->pool, + "Can't parse expression : ", err, NULL); + } + return NULL; + } + else if (arg_ == ap_strstr_c(arg_, "proxy:unix")) { dirconf->handler = arg_; } else { @@ -4644,8 +4658,22 @@ 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")) { + r->handler = apr_pstrdup(r->pool, 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