Welcome! Log In Create A New Profile

Advanced

Re: How to make a subrequest from content handler?

Yichun Zhang (agentzh)
February 26, 2015 03:10PM
Hello!

On Thu, Feb 26, 2015 at 4:41 AM, kabirova wrote:
> I have a problem when using subrequest in content handler.
> The content handler (my_content_handler) calls
> ngx_http_read_client_request_body with callback handler (my_callback).
> my_callback() makes a subrequest:
>

Just check out how my ngx_echo module implements its
echo_read_request_body [1] and echo_subrequest [2]. Similarly, our
ngx_lua module implements the ngx.req.read_body() and
ngx.location.capture in the content phase (via content_by_lua).

Maybe you can directly use ngx_echo or ngx_lua for your purposes to
save all the pain on the nginx C land.

> I have 2 questions:
> 1. how to return back to my_content_handler, if it invokes a subrequest?
>

This depends on whether you're doing sync or async subrequests (that
is, whether your content handler needs to wait for the subrequest's
completion). It's hard to explain well in just a few sentences and
your best bet is the existing proven working code out there (see
above).

> 2. how to proxy subrequest's response to client?
>

Both ngx_echo and ngx_lua can do this and the latter has more control
over the subrequest response.

In addition, my ngx_srcache module also uses subrequest extensively
though in an earlier phase (access phase):

https://github.com/openresty/srcache-nginx-module

Still worth a look if you still insist wrestling on the nginx C land :)

Well, good luck!

Best regards,
-agentzh

[1] http://wiki.nginx.org/HttpEchoModule#echo_read_request_body
[2] http://wiki.nginx.org/HttpEchoModule#echo_subrequest

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

How to make a subrequest from content handler?

kabirova 698 February 26, 2015 07:44AM

Re: How to make a subrequest from content handler?

Yichun Zhang (agentzh) 416 February 26, 2015 03:10PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 223
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready