Post Read Request
static int module_post_read_request(request_rec *pReq)
This function is called immediately after the request headers have
been read or, in the case of an internal redirect, synthesized. It is
not called for subrequests. It can return OK
,
DECLINED
, or a status code. If something other
than DECLINED
is returned, no further modules are
called. This can be used to make decisions based purely on the header
content. Currently, the only standard Apache module to use this hook
is the proxy module.
See Example 21-12 for an excerpt from mod_proxy.c.
Example 21-12. mod_proxy.c
static int proxy_detect(request_rec *r) { void *sconf = r->server->module_config; proxy_server_conf *conf; conf = (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module); if (conf->req && r->parsed_uri.scheme) { /* but it might be something vhosted */ if (!(r->parsed_uri.hostname && !strcasecmp(r->parsed_uri.scheme, ap_http_method(r)) && ap_matches_request_vhost(r, r->parsed_uri.hostname, r->parsed_uri.port_str ? r->parsed_uri.port : ap_default_port(r)))) { r->proxyreq = STD_PROXY; r->uri = r->unparsed_uri; r->filename = ap_pstrcat(r->pool, "proxy:", r->uri, NULL); r->handler = "proxy-server"; } } /* We need special treatment for CONNECT proxying: it has no scheme part */ else if (conf->req && r->method_number == M_CONNECT && r->parsed_uri.hostname && r->parsed_uri.port_str) { r->proxyreq = STD_PROXY; r->uri = r->unparsed_uri; r->filename = ap_pstrcat(r->pool, "proxy:", r->uri, NULL); r->handler = "proxy-server"; } return DECLINED; }
This code checks for a request that includes a hostname that does
not match the current virtual host (which, since
it will have been chosen on the basis of the hostname in the request,
means it doesn’t match any virtual host) or a
CONNECT
method (which only proxies use). If either
of these conditions are true, the handler is set to
proxy-server
, and the filename is set to
proxy:
uri
so that the
later phases will be handled by the proxy module.
Apart from minor differences in naming of constants, this function is identical in 2.0.