Some questions about subrequests

Hi.

I would like to add subrequests support in the WSGI module, however I
have some doubts.

What’s the meaning of the NGX_HTTP_ZERO_IN_URI and
NGX_HTTP_SUBREQUEST_IN_MEMORY flags?

Thanks Manlio P.

NGX_HTTP_ZERO_IN_URI:

src/http/ngx_http_core_module.c:
sr->zero_in_uri = (flags & NGX_HTTP_ZERO_IN_URI) != 0;

src/http/ngx_http_request.h:
/* URI with “\0” or “%00” */
unsigned zero_in_uri:1;

Obviously, IMHO.

NGX_HTTP_SUBREQUEST_IN_MEMORY:

src/http/ngx_http_core_module.c:
sr->subrequest_in_memory = (flags & NGX_HTTP_SUBREQUEST_IN_MEMORY) != 0;

src/http/ngx_http_upstream.c:
if (!r->subrequest_in_memory) {
ngx_http_upstream_send_response(r, u);
return;
}

/* subrequest content in memory */

...

So, as I can understand from using-of-subrequests point of view,
r->subrequest_in_memory flag tells ngx_http_upstream_module to save a
pointer to the full chain of response buffers in r->upstream->out_bufs
chain-link. And not-to-free that buffers after subrequest was
finished.

Fix me, if I’m wrong.

Sergey B. ha scritto:

Yes, this was easy!

}

Fix me, if I’m wrong.

I’m not sure, but it seems that I can safely set flags to 0.

I have one more, important, question.
When will be the post_subrequest->handler called?
Always after ngx_http_subrequest returns?

Thanks Manlio P.

Sergey B. ha scritto:

[…]

If you need to keep the upstream response in memory,
NGX_HTTP_SUBREQUEST_IN_MEMORY flag may be useful for you. You can
also set the r->filter_need_in_memory flag in header-filter and read
full response body in the body-filter.

Thanks, but I don’t think I have the need to keep it in memory;
it will complicate the implementation.

The handler will be called after the end of the subrequest, not the
end of ngx_http_subrequest()-function call.

The problem is that you are assuming that the subrequest will make use
of the upstream module, but this is not always the case.

What happens if the subrequest will make use of the static module and
the file is very small?

Here you can find the appropriate discussion (unfortunately, in
russian): http://article.gmane.org/gmane.comp.web.nginx.russian/11160

Thanks Manlio P.

Manlio P. ha scritto:

the file is very small?

Confirmed, if the subrequest handler returns without NGX_AGAIN, then the
callback is called before the ngx_http_subrequest function returns.

Manlio P.

On Fri, 28 Mar 2008 13:21:31 +0100
Manlio P. [email protected]
wrote:

Obviously, IMHO.
src/http/ngx_http_upstream.c:
r->subrequest_in_memory flag tells ngx_http_upstream_module to save a
pointer to the full chain of response buffers in r->upstream->out_bufs
chain-link. And not-to-free that buffers after subrequest was
finished.

Fix me, if I’m wrong.

I’m not sure, but it seems that I can safely set flags to 0.

If you need to keep the upstream response in memory,
NGX_HTTP_SUBREQUEST_IN_MEMORY flag may be useful for you. You can
also set the r->filter_need_in_memory flag in header-filter and read
full response body in the body-filter.

I have one more, important, question.
When will be the post_subrequest->handler called?
Always after ngx_http_subrequest returns?

The ngx_http_subrequest()-function is asyncronous and returns
immediately after all appropriate fields of ngx_http_request_t
structure will be filled. It doesn’t wait for any upstream answer at
all.

The handler will be called after the end of the subrequest, not the
end of ngx_http_subrequest()-function call.

Here you can find the appropriate discussion (unfortunately, in
russian): http://article.gmane.org/gmane.comp.web.nginx.russian/11160

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs