Handling a subrequest response - determining upstream vs. static file and size

최영석 zealot33 at gmail.com
Tue Mar 20 08:04:16 UTC 2012


Hi.

You can refer echo-nginx-module written by agentzh.
There's a *ngx_http_echo_subrequest.c *file in
https://github.com/agentzh/echo-nginx-module

There's lots of sub-request handling code in this file.
I'm on the way of reading this module.
Since the subrequest is itself a request.
There's no difference with getting response body size of a normal request.

272 if (body_str != NULL && body_str->len) {
273        rb = ngx_pcalloc(r->pool, sizeof(ngx_http_request_body_t));
274
275        if (rb == NULL) {
276            return NGX_HTTP_INTERNAL_SERVER_ERROR;
277        }
278
279        parsed_sr->content_length_n = body_str->len;
280
281        b = ngx_calloc_buf(r->pool);
282        if (b == NULL) {
283            return NGX_HTTP_INTERNAL_SERVER_ERROR;
284        }


To extract a subrequest from a request, I guess there's a function named
ngx_http_subrequest in ngx_http_core_module.c

Hope this can help you!

2012/3/20 Brian Moran <bmoran at onehub.com>

> Sorry about that, inadvertently hit send...
>
> I am modifying an existing working filter module. I am issuing a
> subrequest, which is to a URI, or to a static local file (via a location in
> the config); I'd like to determine the size of the response that I'm
> getting back from the subrequest.
>
> In the subrequest's header filter, I'm doing this to find out the response
> size:
> if (r->upstream) {
>    response_size = r->upstream->headers_in.content_length_n;
>  ...
> }
>
> For the subrequests that result in the static file being streamed from
> disk, r->upstream is NULL.
> What's the right nginx way to determine in my filter what the size of the
> 'body' part of the subrequest response is going to be?
>
> Thanks!
>
>
> On Mon, Mar 19, 2012 at 9:31 PM, Brian Moran <bmoran at onehub.com> wrote:
>
>> --
>> e: bmoran at onehub.com
>> p: +1 206 390 4376
>>
>> Onehub, Inc.
>> www.onehub.com
>>
>>
>
>
> --
> e: bmoran at onehub.com
> p: +1 206 390 4376
>
> Onehub, Inc.
> www.onehub.com
>
>
> _______________________________________________
> nginx-devel mailing list
> nginx-devel at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20120320/edb16992/attachment-0001.html>


More information about the nginx-devel mailing list