A problem with PHP request rewriting

Source: Internet
Author: User
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

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.