catching 408 response from upstream server

shmulik nginx-forum at nginx.us
Wed Feb 11 20:47:52 UTC 2015


Hi,

Below is the debug_http log showing the same location handling upstream
response of 409, and next of 408.
You can see that the 408 response is handled differently:

// ----------------409 -------------- //

2015/02/11 22:07:03 [debug] 20611#0: *3 http upstream process header        
                                                              
2015/02/11 22:07:03 [debug] 20611#0: *3 http proxy header done              
                                                              
2015/02/11 22:07:03 [debug] 20611#0: *3 finalize http upstream request: 409
2015/02/11 22:07:03 [debug] 20611#0: *3 finalize http proxy request
2015/02/11 22:07:03 [debug] 20611#0: *3 free rr peer 1 0
2015/02/11 22:07:03 [debug] 20611#0: *3 close http upstream connection: 12
2015/02/11 22:07:03 [debug] 20611#0: *3 http finalize request: 409,
"/proxy/host_www.a.com/fallback_www.b.com/" a:1, c:1
2015/02/11 22:07:03 [debug] 20611#0: *3 http special response: 409,
"/proxy/host_www.a.com/fallback_www.b.com/" // <-- handled as special
response 
2015/02/11 22:07:03 [debug] 20611#0: *3 http script var:
"http://www.b.com/"
2015/02/11 22:07:03 [debug] 20611#0: *3 http log handler
2015/02/11 22:07:03 [debug] 20611#0: *3 HTTP/1.1 302 Moved Temporarily
Server: nginx
Date: Wed, 11 Feb 2015 20:07:03 GMT
Content-Type: text/html
Content-Length: 149
Connection: keep-alive
Location: http://www.b.com/


// ------------- 408 -------------- //

2015/02/11 22:05:03 [debug] 20611#0: *1 http upstream process header
2015/02/11 22:05:03 [debug] 20611#0: *1 http proxy header done
2015/02/11 22:05:03 [debug] 20611#0: *1 finalize http upstream request: 408
2015/02/11 22:05:03 [debug] 20611#0: *1 finalize http proxy request
2015/02/11 22:05:03 [debug] 20611#0: *1 free rr peer 1 0
2015/02/11 22:05:03 [debug] 20611#0: *1 close http upstream connection: 12
2015/02/11 22:05:03 [debug] 20611#0: *1 http finalize request: 408,
"/proxy/host_www.a.com/fallback_www.b.com/" a:1, c:1
2015/02/11 22:05:03 [debug] 20611#0: *1 http terminate request count:1 //
<-- handled by terminating the connection
2015/02/11 22:05:03 [debug] 20611#0: *1 http terminate cleanup count:1
blk:0
2015/02/11 22:05:03 [debug] 20611#0: *1 http posted request:
"/proxy/host_www.a.com/fallback_www.b.com/"
2015/02/11 22:05:03 [debug] 20611#0: *1 http terminate handler count:1
2015/02/11 22:05:03 [debug] 20611#0: *1 http request count:1 blk:0
2015/02/11 22:05:03 [debug] 20611#0: *1 http close request

I've tried to follow this in code (by the way, i'm using version 1.6.2,
sorry i didn't mention it earlier).
It seems that indeed response code 408 is handled differently. in function
"ngx_http_finalize_request" i can see that code 408 is handled by calling
"ngx_http_terminate_request", while other codes (like 409) are handled a few
lines later with "ngx_http_special_response_handler" which also handles the
error_page directive.

I've read in a different post in this forum that Nginx, by design,
terminates the connection when it's configured to respond with 408 response
code - for example when using "return 408" in a location. The post can be
found here: http://forum.nginx.org/read.php?2,173195,173235#msg-173235

However in my case, i'm not generating an 408 response in Nginx. I'm trying
to catch an 408 response from the upstream server, and turn it into a
redirect.

As you said, the documentation doesn't say anything about error_page
handling response code 408 differently, so i can't figure out if this
behavior is intentional or not.

If intentional - i'd really like to understand the logic behind it, perhaps
i'm looking at it all wrong.
If it's not intentional - i'd really like to find a way around this, to
return a redirect to the client.

Thank you for your patience and help,
ShmulikB

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,256530,256597#msg-256597



More information about the nginx mailing list