Handling a subrequest response - determining upstream vs. static file and size
Maxim Dounin
mdounin at mdounin.ru
Tue Mar 20 08:21:38 UTC 2012
Hello!
On Mon, Mar 19, 2012 at 09:34:56PM -0700, Brian Moran wrote:
> 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?
In both cases correct way to estimate response size (if known) is
to check r->headers_out->content_length_n. Note well: it may be
set to -1, which means response size isn't known.
Maxim Dounin
More information about the nginx-devel
mailing list