or a message. Apache httpd will sometimes offer additional information
regarding the problem/error.</p>
+ <p>From 2.4.13, <a href="../expr.html">expression syntax</a> can be
+ used inside the directive to produce dynamic strings and URLs.</p>
+
<p>URLs can begin with a slash (/) for local web-paths (relative
to the <directive module="core">DocumentRoot</directive>), or be a
full URL which the client can resolve. Alternatively, a message
- can be provided to be displayed by the browser. Examples:</p>
+ can be provided to be displayed by the browser. Note that deciding
+ whether the parameter is an URL, a path or a message is performed
+ before any expression is parsed. Examples:</p>
<highlight language="config">
ErrorDocument 500 http://foo.example.com/cgi-bin/tester
ErrorDocument 401 /subscription_info.html
ErrorDocument 403 "Sorry can't allow you access today"
ErrorDocument 403 Forbidden!
+ErrorDocument 403 /cgi-bin/forbidden.pl?referrer=%{escape:%{HTTP_REFERER}}
</highlight>
<p>Additionally, the special value <code>default</code> can be used
conf->override_list = new->override_list;
}
- if (conf->response_code_strings == NULL) {
- conf->response_code_strings = new->response_code_strings;
+ if (conf->response_code_exprs == NULL) {
+ conf->response_code_exprs = new->response_code_exprs;
}
- else if (new->response_code_strings != NULL) {
- /* If we merge, the merge-result must have its own array
- */
- conf->response_code_strings = apr_pmemdup(a,
- base->response_code_strings,
- sizeof(*conf->response_code_strings) * RESPONSE_CODES);
-
- for (i = 0; i < RESPONSE_CODES; ++i) {
- if (new->response_code_strings[i] != NULL) {
- conf->response_code_strings[i] = new->response_code_strings[i];
- }
- }
+ else if (new->response_code_exprs != NULL) {
+ conf->response_code_exprs = apr_hash_overlay(a,
+ new->response_code_exprs, conf->response_code_exprs);
}
- /* Otherwise we simply use the base->response_code_strings array
+ /* Otherwise we simply use the base->response_code_exprs array
*/
if (new->hostname_lookups != HOSTNAME_LOOKUP_UNSET) {
{
core_dir_config *dirconf;
core_request_config *reqconf = ap_get_core_module_config(r->request_config);
+ const char *err;
+ const char *response;
+ void *val;
+ ap_expr_info_t *expr;
/* check for string registered via ap_custom_response() first */
- if (reqconf->response_code_strings != NULL &&
- reqconf->response_code_strings[error_index] != NULL) {
+ if (reqconf->response_code_strings != NULL
+ && reqconf->response_code_strings[error_index] != NULL) {
return reqconf->response_code_strings[error_index];
}
/* check for string specified via ErrorDocument */
dirconf = ap_get_core_module_config(r->per_dir_config);
- if (dirconf->response_code_strings == NULL) {
+ if (!dirconf->response_code_exprs) {
+ return NULL;
+ }
+
+ expr = apr_hash_get(dirconf->response_code_exprs, &error_index,
+ sizeof(error_index));
+ if (!expr) {
return NULL;
}
- if (dirconf->response_code_strings[error_index] == &errordocument_default) {
+ /* special token to indicate revert back to default */
+ if ((char *) expr == &errordocument_default) {
return NULL;
}
- return dirconf->response_code_strings[error_index];
+ err = NULL;
+ response = ap_expr_str_exec(r, expr, &err);
+ if (err) {
+ ap_log_rerror(
+ APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(02830) "core: ErrorDocument: can't "
+ "evaluate require expression: %s", err);
+ return NULL;
+ }
+
+ /* alas, duplication required as we return not-const */
+ return apr_pstrdup(r->pool, response);
}
"directive --- ignoring!", cmd->directive->filename, cmd->directive->line_num);
}
else { /* Store it... */
- if (conf->response_code_strings == NULL) {
- conf->response_code_strings =
- apr_pcalloc(cmd->pool,
- sizeof(*conf->response_code_strings) *
- RESPONSE_CODES);
+ if (conf->response_code_exprs == NULL) {
+ conf->response_code_exprs = apr_hash_make(cmd->pool);
}
if (strcasecmp(msg, "default") == 0) {
/* special case: ErrorDocument 404 default restores the
* canned server error response
*/
- conf->response_code_strings[index_number] = &errordocument_default;
+ apr_hash_set(conf->response_code_exprs,
+ apr_pmemdup(cmd->pool, &index_number, sizeof(index_number)),
+ sizeof(index_number), &errordocument_default);
}
else {
+ ap_expr_info_t *expr;
+ const char *expr_err = NULL;
+
/* hack. Prefix a " if it is a msg; as that is what
* http_protocol.c relies on to distinguish between
* a msg and a (local) path.
*/
- conf->response_code_strings[index_number] = (what == MSG) ?
- apr_pstrcat(cmd->pool, "\"", msg, NULL) :
- apr_pstrdup(cmd->pool, msg);
+ const char *response =
+ (what == MSG) ? apr_pstrcat(cmd->pool, "\"", msg, NULL) :
+ apr_pstrdup(cmd->pool, msg);
+
+ expr = ap_expr_parse_cmd(cmd, response, AP_EXPR_FLAG_STRING_RESULT,
+ &expr_err, NULL);
+
+ if (expr_err) {
+ return apr_pstrcat(cmd->temp_pool,
+ "Cannot parse expression in ErrorDocument: ",
+ expr_err, NULL);
+ }
+
+ apr_hash_set(conf->response_code_exprs,
+ apr_pmemdup(cmd->pool, &index_number, sizeof(index_number)),
+ sizeof(index_number), expr);
+
}
}