php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43843 Documentation sites return HTTP/1.1 even if 1.0 requested -> Garbage in Output
Submitted: 2008-01-14 18:18 UTC Modified: 2008-01-17 19:18 UTC
From: php dot net at thermoman dot de Assigned: thekid (profile)
Status: Closed Package: Website problem
PHP Version: Irrelevant OS: Irrelevant
Private report: No CVE-ID: None
 [2008-01-14 18:18 UTC] php dot net at thermoman dot de
Description:
------------
On php.net Doc sites (e.g. http://php.net/print_r) the scripts return a HTTP/1.1 header even if the client requested HTTP/1.0

This leads to Content-Transfer-Encoding metadata being inserted into the websites body.

Reproduce code:
---------------
  $ telnet php3.de 80
  Trying 217.160.72.57...
  Connected to php3.de.
  Escape character is '^]'.
  HEAD /print_r HTTP/1.0
  Connection: close
  Host: de3.php.net

  HTTP/1.1 200 OK
  [..]

Expected result:
----------------
HTTP/1.0 200 OK

Actual result:
--------------
The header is generated at this point:

== schnipp == 
// Send out a proper status header
function status_header($num)
{
    // Set status text
    switch ($num) {
        case 200: $status = "OK"; break;
        case 301: $status = "Moved Permanently"; break;
        case 302: $status = "Found"; break;
        case 404: $status = "Not Found"; break;
        default: return FALSE;
    }

    // BC code for PHP < 4.3.0
    @header("HTTP/1.1 $num $status");
    @header("Status: $num $status", TRUE, $num);

    return TRUE;
}
== schnapp ==

See http://trac.wordpress.org/ticket/3886 for the exact same problem including a patch for older wordpress versions.

Here is a screenshot of the website with garbage in it when requested via squid proxy server with HTTP/1.0:

  http://test.thermoman.de/images/php_net_chunked_error.png

Please cross-reference bug #42402.

Credits to Timm Friebe for the deeper look inside.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-01-15 15:47 UTC] thekid@php.net
This patch could fix it:

php3:/home/httpd/php3.de/doc_root/include# diff -u errors.inc ~/errors.inc.fixed 
--- errors.inc  Tue Jan 15 16:46:23 2008
+++ /root/errors.inc.fixed      Tue Jan 15 16:45:57 2008
@@ -75,8 +75,13 @@
         default: return FALSE;
     }
     
+    // Figure out HTTP protocol version - use 1.1 answer for 1.1 request,
+    // answer with HTTP/1.0 for any other (ancient or futuristic) user agent 
+    switch (strtoupper($_ENV['SERVER_PROTOCOL'])) {
+       case 'HTTP/1.1': @header("HTTP/1.1 $num $status"); break;
+       case 'HTTP/1.0': default: @header("HTTP/1.0 $num $status"); break; 
+    }
     // BC code for PHP < 4.3.0
-    @header("HTTP/1.1 $num $status");
     @header("Status: $num $status", TRUE, $num);
     
     return TRUE;

 [2008-01-16 10:55 UTC] thekid@php.net
Hrm, instead of $_ENV it needs to be $_SERVER.
 [2008-01-17 19:18 UTC] bjori@php.net
This bug has been fixed in CVS. Since the websites are not directly
updated from the CVS server, the fix might need some time to spread
across the globe to all mirror sites, including PHP.net itself.

Thank you for the report, and for helping us make PHP.net better.

Thanks for analyzing and the patch!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 02:01:29 2024 UTC