Post action after client closes connection

This is my scenario:

  • client connects to nginx (proxy_ignore_client_abort is on at this
  • nginx sends data from upstream (received by subrequests) back to
  • 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:, server: localhost, request: “GET
/download/plik2 HTTP/1.0”, upstream:”, host: “localhost”
2009/04/29 15:09:46 [debug] 13740#0: *7 http finalize request: 0,
2009/04/29 15:09:46 [debug] 13740#0: *7 post action:
2009/04/29 15:09:46 [debug] 13740#0: *7 internal redirect:

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:, 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,
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,

Just wanted to add that subrequests are performed from filter (in a
while loop) like in Emiller’s Guide:

I think I have found solution :slight_smile:

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 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