Bug #55010 [Opn->Dup]: POST requests send 4 extra bytes
| From: | scottmac@php.net | Date: | Wed, 08 Jun 2011 16:08:45 +0000 |
| Subject: | Bug #55010 [Opn->Dup]: POST requests send 4 extra bytes | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-161245@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=55010&edit=1
ID: 55010
Updated by: scottmac@php.net
Reported by: fidian at rumkin dot com
Summary: POST requests send 4 extra bytes
-Status: Open
+Status: Duplicate
Type: Bug
Package: HTTP related
Operating System: Ubuntu 11.04
PHP Version: 5.3.6
Block user comment: N
Private report: N
New Comment:
Was fixed in Bug #54137
Previous Comments:
------------------------------------------------------------------------
[2011-06-08 18:01:21] fidian at rumkin dot com
Description:
------------
PHP sends 4 extra bytes with a POST request when using stream_context_create and
file_get_contents. The extra bytes are CR LF CR LF. The RFC does not state that
CR LF CR LF should be after message-body.
This appears to be the same as Bug #43222: stream_context_create() bugs
Was there a test created to detect this problem?
Test script:
---------------
$url = 'http://localhost:8001/post';
$post = 'Sample'; // 6 bytes
$options = array(
'http' => array(
'method' => 'POST',
'protocol_version' => '1.1',
'content' => $post,
)
);
$urlParts = parse_url($url);
$headers = array();
$headers[] = 'Content-Type: application/x-www-form-urlencoded; charset=utf-8';
$headers[] = 'Content-Length: ' . strlen($post);
$headers[] = 'Connection: close'; // Force servers to close the connection
$headers[] = 'Host: ' . $urlParts['host']; // Required for HTTP 1.1
$options['http']['header'] = $headers;
$context = stream_context_create($options);
file_get_contents($url, false, $context);
Expected result:
----------------
The hexdump of the TCP traffic should appear like thus:
00000000 50 4f 53 54 20 2f 70 6f 73 74 20 48 54 54 50 2f |POST /post HTTP/|
00000010 31 2e 31 0d 0a 43 6f 6e 74 65 6e 74 2d 54 79 70 |1.1..Content-Typ|
00000020 65 3a 20 61 70 70 6c 69 63 61 74 69 6f 6e 2f 78 |e: application/x|
00000030 2d 77 77 77 2d 66 6f 72 6d 2d 75 72 6c 65 6e 63 |-www-form-urlenc|
00000040 6f 64 65 64 3b 20 63 68 61 72 73 65 74 3d 75 74 |oded; charset=ut|
00000050 66 2d 38 0d 0a 43 6f 6e 74 65 6e 74 2d 4c 65 6e |f-8..Content-Len|
00000060 67 74 68 3a 20 36 0d 0a 43 6f 6e 6e 65 63 74 69 |gth: 6..Connecti|
00000070 6f 6e 3a 20 63 6c 6f 73 65 0d 0a 48 6f 73 74 3a |on: close..Host:|
00000080 20 6c 6f 63 61 6c 68 6f 73 74 0d 0a 0d 0a 53 61 | localhost....Sa|
00000090 6d 70 6c 65 |mple|
00000094
Actual result:
--------------
This is what I actually capture as TCP traffic
00000000 50 4f 53 54 20 2f 70 6f 73 74 20 48 54 54 50 2f |POST /post HTTP/|
00000010 31 2e 31 0d 0a 43 6f 6e 74 65 6e 74 2d 54 79 70 |1.1..Content-Typ|
00000020 65 3a 20 61 70 70 6c 69 63 61 74 69 6f 6e 2f 78 |e: application/x|
00000030 2d 77 77 77 2d 66 6f 72 6d 2d 75 72 6c 65 6e 63 |-www-form-urlenc|
00000040 6f 64 65 64 3b 20 63 68 61 72 73 65 74 3d 75 74 |oded; charset=ut|
00000050 66 2d 38 0d 0a 43 6f 6e 74 65 6e 74 2d 4c 65 6e |f-8..Content-Len|
00000060 67 74 68 3a 20 36 0d 0a 43 6f 6e 6e 65 63 74 69 |gth: 6..Connecti|
00000070 6f 6e 3a 20 63 6c 6f 73 65 0d 0a 48 6f 73 74 3a |on: close..Host:|
00000080 20 6c 6f 63 61 6c 68 6f 73 74 0d 0a 0d 0a 53 61 | localhost....Sa|
00000090 6d 70 6c 65 0d 0a 0d 0a |mple....|
00000098
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=55010&edit=1