Help with reading response from upstream u->buffer
Ashish S
ashishs.dev at gmail.com
Thu Apr 26 00:22:05 UTC 2012
Hi there,
In my module which uses upstream to talk to a backend, i do the
following in the response processing method (u->process_header)
{
ngx_http_upstream_t * u = r->upstream;
size_t myResponseLength = (u->buffer.last - u->buffer.pos);
size_t origUpstreamResponseLength = (u->buffer.last - u->buffer.start);
std::string myResponseString ((u_char *) u->buffer.pos, myResponseLength);
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "u->length is %d
and Original Upstream response length is %d and myResponseLength is
%d", u->length, origUpstreamResponseLength, myResponseLength);
....
}
My actual response length from upstream is ~16kb, while i get
u->length printed as 0, Original upstream response length and
myResponseLength printed as 1448 bytes. I also see in nginx debug
logs, "Transfer-Encoding: chunked". Is the difference in length
printed, because of this encoding? Is there a way to disable chunked
transfer, so that i can get the entire response in one go (into my
string), as shown in code? If not, what is the right method to read
the entire response from upstream buffer into a temporary string (so
that i can do further parsing)?
Thanks,
Ashish
More information about the nginx
mailing list