httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Graham Leggett <minf...@sharp.fm>
Subject Re: Inserting a request in the middle of another one
Date Tue, 06 Nov 2012 12:56:17 GMT
On 05 Nov 2012, at 1:31 PM, Nick Gearls <nickgearls@gmail.com> wrote:

> I'd like to insert a request in the middle of another one.
> 
> Example:
>    request ------> httpd(proxy mode) ---------> web site
> should become
>    request ------> httpd(receive) --> external request --> httpd(send) --------->
web site
> 
> I obviously need to send my external request based on the received request and modify
it before proxying it based on the output of my external request - otherwise it would be too
simple ;-)
> 
> What would be the best approach?
> I can write a module to send an external HTTP request, that's not a big issue.
> I can get all info from the originating request in httpd structures, that's rather easy.
> However, do I have any facilities to send/receive the HTTP external request? I can send
it with bare buckets, but I would need manually parse the result; this would be heavy. Is
there any easier way (like using mod_proxy) to get some higher level access to the result
headers (for instance)?

The way I've done this in the past is create a subrequest, then replace the input and output
filter stacks with either null filters, or a filter that parses the output, and then run the
subrequest, something like this.

Ideally this should be an API of some kind.

        rr = ap_sub_req_method_uri("GET", target, r, NULL);
        ap_parse_uri(rr, target);

        if (rr->status != HTTP_OK) {
            /* log error */
            return rr->status;
        }

        /* disassociate from the main request */
        rr->main = NULL;
        rr->output_filters = NULL;
        ap_add_output_filter("NULL", NULL, rr, r->connection);
        rr->input_filters = NULL;
        ap_add_input_filter("NULL", NULL, rr, r->connection);

        /* emulate proxy_detect so that a remote proxy request will be attempted */
        rr->proxyreq = PROXYREQ_PROXY;
        rr->uri = rr->unparsed_uri;
        rr->filename = apr_pstrcat(rr->pool, "proxy:", rr->uri, NULL);
        rr->handler = "proxy-server";

        if ((status = ap_run_sub_req(rr))) {
            /* log error */
            return status;
        }

Regards,
Graham
--


Mime
View raw message