A problem with PHP request rewriting
My colleague asked me to help explain a problem: a PHP-generated redirect request produces two distinct records in the Nginx log: One response body size is 0 bytes, and the other response body size is five bytes.
Now older, the face of the problem of the sense of smell is no longer sensitive, the first feeling 0 is correct, thought is not redirected after forgetting to quit, but also after the content output, but checked the code found no problem:
1
2
3
4
Header (' Location:/path ');
Exit
?>
After a big round, I suddenly realized that the environment is nginx+php, the response is not "content-length", the data is sent through the "transfer-encoding" block, so the redirected empty response body is actually similar:
0\r\n\r\n
Not too much, just five bytes, details can refer to chunked transfer encoding. So it seems that in the case of such an empty response, PHP might be better off actively outputting a "content-length:0".
How does the 0-byte response explain it? The query log finds the following two scenarios:
HEAD "/path http/1.1" 302 0
GET "/path http/1.0" 302 0
The former is the head request, the response body is not required, the latter is http/1.0 and does not support "transfer-encoding".
The basic explanation of the problem, wipe the sweat of the forehead, and finally did not lose face in front of colleagues.
Turn from: A small HTTP problem