You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Doug MacEachern <do...@pobox.com> on 1998/08/04 20:57:04 UTC

ap_custom_response()

For sometime now, mod_perl has had an $r->custom_response() method which
hooks into the ErrorDocument mechanism at runtime.  This has proved quite
useful and popular, works like so:

/* print this string if NOT_FOUND error is thrown */
ap_custom_response(NOT_FOUND, "Sorry, can't find that");

/* run this url if NOT_FOUND error is thrown */
ap_custom_response(NOT_FOUND, "/error_scripts/not_found.pl");

Thoughts on adding this function to 1.3.2-dev?

-Doug

API_EXPORT(void) ap_custom_response(request_rec *r, int status, char *string)
{
    core_dir_config *conf =
        ap_get_module_config(r->per_dir_config, &core_module);
    int idx;

    if(conf->response_code_strings == NULL) {
        conf->response_code_strings =
            ap_pcalloc(r->pool,
                    sizeof(*conf->response_code_strings) *
                    RESPONSE_CODES);
    }

    idx = ap_index_of_response(status);

    conf->response_code_strings[idx] =
       ((ap_is_url(string) || (*string == '/')) && (*string != '"')) ?
       ap_pstrdup(r->pool, string) : ap_pstrcat(r->pool, "\"", string, NULL);
}