From e739a90d8ef41445880449439aeedb5767fce5f0 Mon Sep 17 00:00:00 2001 From: Jim Jagielski Date: Thu, 11 Feb 2016 19:06:16 +0000 Subject: [PATCH] Merge r1725149, r1726233, r1729374, r1729374 from trunk: 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 | 2 ++ STATUS | 10 ---------- docs/manual/mod/core.xml | 12 ++++++++++- include/ap_mmn.h | 3 ++- include/http_core.h | 4 ++-- server/core.c | 43 ++++++++++++++++++++++++++++++---------- 6 files changed, 50 insertions(+), 24 deletions(-) diff --git a/CHANGES b/CHANGES index 3a0193825a..a69519976d 100644 --- 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 3f28ae73a6..910b37b133 100644 --- 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 diff --git a/docs/manual/mod/core.xml b/docs/manual/mod/core.xml index 7089893f09..3b8b6c9305 100644 --- a/docs/manual/mod/core.xml +++ b/docs/manual/mod/core.xml @@ -4173,11 +4173,12 @@ header SetHandler Forces all matching files to be processed by a handler -SetHandler handler-name|None +SetHandler handler-name|none|expression server configvirtual host directory.htaccess FileInfo +2.4.19 and later

When placed into an .htaccess file or a @@ -4212,6 +4213,15 @@ handler </FilesMatch> +

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

+ + +<LocationMatch ^/app/(?<sub>[^/]+)/> + SetHandler "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 3233ef8027..aa6dfd080d 100644 --- a/include/ap_mmn.h +++ b/include/ap_mmn.h @@ -457,6 +457,7 @@ * 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" */ @@ -464,7 +465,7 @@ #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 diff --git a/include/http_core.h b/include/http_core.h index 85354552c1..97cb864072 100644 --- a/include/http_core.h +++ b/include/http_core.h @@ -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 */ diff --git a/server/core.c b/server/core.c index 9ee2638f50..4dd8200d36 100644 --- a/server/core.c +++ b/server/core.c @@ -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 -- 2.40.0