Forum: NGINX Post action after client closes connection

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Roman M. (Guest)
on 2009-04-29 18:48
Hello,
This is my scenario:
* client connects to nginx (proxy_ignore_client_abort is on at this
location)
* nginx sends data from upstream (received by subrequests) back to
client
* when request finishes I want to send confirmation using GET method to
other upstream
Everything is ok when client downloads all data, then I'm using:
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
clcf->post_action = location of upstream
and rest is done during finalization of main request. Great.

The problem is when client closes connection during download. If it
happens during main request it is handled properly:

2009/04/29 15:09:46 [debug] 13740#0: *7 http test reading
2009/04/29 15:09:46 [info] 13740#0: *7 client closed prematurely
connection, client: 127.0.0.1, server: localhost, request: "GET
/download/plik2 HTTP/1.0", upstream:
"http://192.168.0.3:80/prox.php?file=plik2", host: "localhost"
2009/04/29 15:09:46 [debug] 13740#0: *7 http finalize request: 0,
"/prox.php?file=plik2"
2009/04/29 15:09:46 [debug] 13740#0: *7 post action:
"/postdownload/file/user/status"
2009/04/29 15:09:46 [debug] 13740#0: *7 internal redirect:
"/postdownload/file/user/status?"

But if it happens during subrequest, post action isn't activated:

2009/04/29 13:55:06 [debug] 12147#0: *13 http test reading
2009/04/29 13:55:06 [info] 12147#0: *13 client closed prematurely
connection, client: 127.0.0.1, server: localhost, request: "GET
/download/plik2 HTTP/1.0", subrequest: "/send", host: "localhost"
2009/04/29 13:55:06 [debug] 12147#0: *13 http finalize request: 0,
"/send?"
2009/04/29 13:55:06 [debug] 12147#0: *13 http close request
2009/04/29 13:55:06 [debug] 12147#0: *13 http log handler
2009/04/29 13:55:06 [debug] 12147#0: *13 free: 08FA3660

I have even tried setting own handler for ngx_http_post_subrequest_t in
subrequest and initate from it another subrequest to upstream to confirm
download status, but then it doesn't seem to work (nothing is sent).

Any ideas?

Thanks in advance,
mobczynski
Roman M. (Guest)
on 2009-05-04 11:22
Just wanted to add that subrequests are performed from filter (in a
while loop) like in Emiller's Guide:
http://www.evanmiller.org/nginx-modules-guide.html...
Roman M. (Guest)
on 2009-05-04 13:21
I think I have found solution :)

ngx_http_request_t *sr;
rc = ngx_http_subrequest(r, &location, NULL, &sr, NULL, 0);

ngx_http_core_loc_conf_t  *clcfsub;

//location configuration for subrequest
clcfsub = ngx_http_get_module_loc_conf(sr, ngx_http_core_module);

clcfsub->post_action = uri of post action;

Earlier I was setting post_action only for main request and now it is
set also for subrequest, seems to work.
This topic is locked and can not be replied to.