ASF Bugzilla – Attachment 36701 Details for
Bug 63628
Support specifying the http status codes to be considered by ProxyErrorOverride
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch to support specifying the http status codes to be considered by ProxyErrorOverride
proxy_error_intercept.patch (text/plain), 12.11 KB, created by
Martin Drößler
on 2019-08-02 13:09:28 UTC
(
hide
)
Description:
Patch to support specifying the http status codes to be considered by ProxyErrorOverride
Filename:
MIME Type:
Creator:
Martin Drößler
Created:
2019-08-02 13:09:28 UTC
Size:
12.11 KB
patch
obsolete
>Index: docs/manual/mod/mod_proxy.xml >=================================================================== >--- docs/manual/mod/mod_proxy.xml (Revision 1864219) >+++ docs/manual/mod/mod_proxy.xml (Arbeitskopie) >@@ -2050,6 +2050,34 @@ > </directivesynopsis> > > <directivesynopsis> >+<name>ProxyErrorIntercept</name> >+<description>Specify the HTTP Status Codes for which error pages for proxied content shall be overridden</description> >+<syntax>ProxyErrorIntercept <var>code</var> [<var>code</var>] ...</syntax> >+<default>empty</default> >+<contextlist><context>server config</context><context>virtual host</context> >+<context>directory</context> >+</contextlist> >+ >+<usage> >+ <p>This directive can be used in combination with <directive>ProxyErrorOverride</directive> in order to have >+ more control over the status codes being affected.</p> >+ >+ <p>By default <directive>ProxyErrorOverride</directive> affects all responses with codes between 400 (including) >+ and 600 (excluding).</p> >+ >+ <p>Using this directive will change the default behaviour and makes <directive>ProxyErrorOverride</directive> >+ only consider the specified status codes.</p> >+ >+ <example><title>Example</title> >+ <highlight language="config"> >+ ProxyErrorOverride On >+ ProxyErrorIntercept 403 405 500 501 502 503 504 >+ </highlight> >+ </example> >+</usage> >+</directivesynopsis> >+ >+<directivesynopsis> > <name>ProxyPassInterpolateEnv</name> > <description>Enable Environment Variable interpolation in Reverse Proxy configurations</description> > <syntax>ProxyPassInterpolateEnv On|Off</syntax> >Index: modules/proxy/mod_proxy.c >=================================================================== >--- modules/proxy/mod_proxy.c (Revision 1864219) >+++ modules/proxy/mod_proxy.c (Arbeitskopie) >@@ -1574,6 +1574,7 @@ > new->raliases = apr_array_make(p, 10, sizeof(struct proxy_alias)); > new->cookie_paths = apr_array_make(p, 10, sizeof(struct proxy_alias)); > new->cookie_domains = apr_array_make(p, 10, sizeof(struct proxy_alias)); >+ new->error_intercept_codes = apr_array_make(p, 10, sizeof(proxy_status_code)); > new->preserve_host_set = 0; > new->preserve_host = 0; > new->interpolate_env = -1; /* unset */ >@@ -1604,6 +1605,8 @@ > = apr_array_append(p, base->cookie_paths, add->cookie_paths); > new->cookie_domains > = apr_array_append(p, base->cookie_domains, add->cookie_domains); >+ new->error_intercept_codes >+ = apr_array_append(p, base->error_intercept_codes, add->error_intercept_codes); > new->interpolate_env = (add->interpolate_env == -1) ? base->interpolate_env > : add->interpolate_env; > new->preserve_host = (add->preserve_host_set == 0) ? base->preserve_host >@@ -2122,7 +2125,27 @@ > conf->error_override_set = 1; > return NULL; > } >+ > static const char * >+ set_proxy_error_intercept_codes(cmd_parms *parms, void *dconf, const char *arg) >+{ >+ proxy_dir_conf *conf = dconf; >+ proxy_status_code *sc; >+ >+ if (!apr_isdigit(arg[0])) >+ return "ProxyErrorIntercept: status codes to intercept must be numeric"; >+ >+ int code = strtol(arg, NULL, 10); >+ if (!ap_is_HTTP_VALID_RESPONSE(code)) >+ return "ProxyErrorIntercept: status codes to intercept must be valid HTTP Status Codes"; >+ >+ sc = apr_array_push(conf->error_intercept_codes); >+ sc->status_code = code; >+ >+ return NULL; >+} >+ >+static const char * > add_proxy_http_headers(cmd_parms *parms, void *dconf, int flag) > { > proxy_dir_conf *conf = dconf; >@@ -2707,6 +2730,8 @@ > "Configure Via: proxy header header to one of: on | off | block | full"), > AP_INIT_FLAG("ProxyErrorOverride", set_proxy_error_override, NULL, RSRC_CONF|ACCESS_CONF, > "use our error handling pages instead of the servers' we are proxying"), >+ AP_INIT_ITERATE("ProxyErrorIntercept", set_proxy_error_intercept_codes, NULL, RSRC_CONF|ACCESS_CONF, >+ "use our error handling pages instead of the servers' we are proxying for the specified status codes"), > AP_INIT_FLAG("ProxyPreserveHost", set_preserve_host, NULL, RSRC_CONF|ACCESS_CONF, > "on if we should preserve host header while proxying"), > AP_INIT_TAKE1("ProxyTimeout", set_proxy_timeout, NULL, RSRC_CONF, >Index: modules/proxy/mod_proxy.h >=================================================================== >--- modules/proxy/mod_proxy.h (Revision 1864219) >+++ modules/proxy/mod_proxy.h (Arbeitskopie) >@@ -201,6 +201,9 @@ > unsigned int ppinherit_set:1; > } proxy_server_conf; > >+typedef struct { >+ unsigned int status_code; >+} proxy_status_code; > > typedef struct { > const char *p; /* The path */ >@@ -240,6 +243,8 @@ > /** Named back references */ > apr_array_header_t *refs; > >+ apr_array_header_t *error_intercept_codes; >+ > unsigned int forward_100_continue:1; > unsigned int forward_100_continue_set:1; > } proxy_dir_conf; >@@ -1236,6 +1241,24 @@ > int ap_proxy_lb_workers(void); > > /** >+ * @param conf proxy directory configuration >+ * @param code http status code >+ * @return 1 if code is in the list of error-codes to override, 0 otherwise >+ */ >+int is_proxy_error_intercept_code(proxy_dir_conf *conf, int code); >+ >+/** >+ * Checks if the specified code is an http error code. >+ * When the given proxy directory configuration has custom intercept-codes configured, >+ * only those are considered. Otherwise code is compared against the default error-codes. >+ * >+ * @param conf proxy directory configuration >+ * @param code http status code >+ * @return 1 if code is considered an error-code, 0 otherwise >+ */ >+int is_proxy_error_code(proxy_dir_conf *conf, int code); >+ >+/** > * Return the port number of a known scheme (eg: http -> 80). > * @param scheme scheme to test > * @return port number or 0 if unknown >Index: modules/proxy/mod_proxy_ajp.c >=================================================================== >--- modules/proxy/mod_proxy_ajp.c (Revision 1864219) >+++ modules/proxy/mod_proxy_ajp.c (Arbeitskopie) >@@ -474,7 +474,7 @@ > /* If we are overriding the errors, we can't put the content > * of the page into the brigade. > */ >- if (!conf->error_override || !ap_is_HTTP_ERROR(r->status)) { >+ if (!conf->error_override || !is_proxy_error_code(conf, r->status)) { > /* AJP13_SEND_BODY_CHUNK with zero length > * is explicit flush message > */ >@@ -497,8 +497,8 @@ > * error status so that an underlying error (eg HTTP_NOT_FOUND) > * doesn't become an HTTP_OK. > */ >- if (conf->error_override && !ap_is_HTTP_ERROR(r->status) >- && ap_is_HTTP_ERROR(original_status)) { >+ if (conf->error_override && !is_proxy_error_code(conf, r->status) >+ && is_proxy_error_code(conf, original_status)) { > r->status = original_status; > r->status_line = original_status_line; > } >@@ -547,7 +547,7 @@ > if (status != APR_SUCCESS) { > backend_failed = 1; > } >- if (!conf->error_override || !ap_is_HTTP_ERROR(r->status)) { >+ if (!conf->error_override || !is_proxy_error_code(conf, r->status)) { > e = apr_bucket_eos_create(r->connection->bucket_alloc); > APR_BRIGADE_INSERT_TAIL(output_brigade, e); > if (ap_pass_brigade(r->output_filters, >@@ -642,7 +642,7 @@ > conn->worker->cp->addr, > conn->worker->s->hostname_ex); > >- if (conf->error_override && ap_is_HTTP_ERROR(r->status)) { >+ if (conf->error_override && is_proxy_error_code(conf, r->status)) { > /* clear r->status for override error, otherwise ErrorDocument > * thinks that this is a recursive error, and doesn't find the > * custom error page >Index: modules/proxy/mod_proxy_fcgi.c >=================================================================== >--- modules/proxy/mod_proxy_fcgi.c (Revision 1864219) >+++ modules/proxy/mod_proxy_fcgi.c (Arbeitskopie) >@@ -772,7 +772,7 @@ > } > > if (conf->error_override >- && ap_is_HTTP_ERROR(r->status) && ap_is_initial_req(r)) { >+ && is_proxy_error_code(conf, r->status) && ap_is_initial_req(r)) { > /* > * set script_error_status to discard > * everything after the headers >Index: modules/proxy/mod_proxy_http.c >=================================================================== >--- modules/proxy/mod_proxy_http.c (Revision 1864219) >+++ modules/proxy/mod_proxy_http.c (Arbeitskopie) >@@ -1618,7 +1618,7 @@ > */ > > /* PR 41646: get HEAD right with ProxyErrorOverride */ >- if (ap_is_HTTP_ERROR(proxy_status) && dconf->error_override) { >+ if (dconf->error_override && is_proxy_error_code(dconf, proxy_status)) { > if (proxy_status == HTTP_UNAUTHORIZED) { > const char *buf; > const char *wa = "WWW-Authenticate"; >@@ -1711,7 +1711,7 @@ > * if we are overriding the errors, we can't put the content > * of the page into the brigade > */ >- if (!dconf->error_override || !ap_is_HTTP_ERROR(proxy_status)) { >+ if (!dconf->error_override || !is_proxy_error_code(dconf, proxy_status)) { > /* read the body, pass it to the output filters */ > apr_read_type_e mode = APR_NONBLOCK_READ; > int finish = FALSE; >@@ -1721,8 +1721,8 @@ > * error status so that an underlying error (eg HTTP_NOT_FOUND) > * doesn't become an HTTP_OK. > */ >- if (dconf->error_override && !ap_is_HTTP_ERROR(proxy_status) >- && ap_is_HTTP_ERROR(original_status)) { >+ if (dconf->error_override && !is_proxy_error_code(dconf, proxy_status) >+ && is_proxy_error_code(dconf, original_status)) { > r->status = original_status; > r->status_line = original_status_line; > } >Index: modules/proxy/mod_proxy_uwsgi.c >=================================================================== >--- modules/proxy/mod_proxy_uwsgi.c (Revision 1864219) >+++ modules/proxy/mod_proxy_uwsgi.c (Arbeitskopie) >@@ -362,9 +362,9 @@ > #if AP_MODULE_MAGIC_AT_LEAST(20101106,0) > dconf = > ap_get_module_config(r->per_dir_config, &proxy_module); >- if (dconf->error_override && ap_is_HTTP_ERROR(r->status)) { >+ if (dconf->error_override && is_proxy_error_code(dconf, r->status)) { > #else >- if (conf->error_override && ap_is_HTTP_ERROR(r->status)) { >+ if (conf->error_override && is_proxy_error_code(conf, r->status)) { > #endif > int status = r->status; > r->status = HTTP_OK; >Index: modules/proxy/proxy_util.c >=================================================================== >--- modules/proxy/proxy_util.c (Revision 1864219) >+++ modules/proxy/proxy_util.c (Arbeitskopie) >@@ -3358,6 +3358,30 @@ > return lb_workers_limit; > } > >+int is_proxy_error_intercept_code(proxy_dir_conf *conf, int code) >+{ >+ if (apr_is_empty_array(conf->error_intercept_codes)) >+ return 0; >+ >+ proxy_status_code *list = (proxy_status_code *) conf->error_intercept_codes->elts; >+ >+ int i; >+ for (i = 0; i < conf->error_intercept_codes->nelts; i++) { >+ if (code == list[i].status_code) >+ return 1; >+ } >+ >+ return 0; >+} >+ >+int is_proxy_error_code(proxy_dir_conf *conf, int code) >+{ >+ if (apr_is_empty_array(conf->error_intercept_codes)) >+ return ap_is_HTTP_ERROR(code); >+ >+ return is_proxy_error_intercept_code(conf, code); >+} >+ > /* deprecated - to be removed in v2.6 */ > PROXY_DECLARE(void) ap_proxy_backend_broke(request_rec *r, > apr_bucket_brigade *brigade)
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 63628
:
36701
|
36979