#43843 [Opn]: Documentation sites return HTTP/1.1 even if 1.0 requested -> Garbage in Output

[email protected]
Newsgroups php.webmaster
Message-ID <[email protected]>
 ID:               43843
 Updated by:       [email protected]
 Reported By:      php dot net at thermoman dot de
 Status:           Open
 Bug Type:         Website problem
 Operating System: Irrelevant
 PHP Version:      Irrelevant
 New Comment:

Hrm, instead of $_ENV it needs to be $_SERVER.


Previous Comments:
------------------------------------------------------------------------

[2008-01-15 15:47:27] [email protected]

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-14 18:18:03] 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.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=43843&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.