httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Doug MacEachern <do...@pobox.com>
Subject ap_custom_response()
Date Tue, 04 Aug 1998 18:57:04 GMT
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);
}


Mime
View raw message