php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55010 POST requests send 4 extra bytes
Submitted: 2011-06-08 18:01 UTC Modified: 2011-06-08 18:08 UTC
From: fidian at rumkin dot com Assigned:
Status: Duplicate Package: HTTP related
PHP Version: 5.3.6 OS: Ubuntu 11.04
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: fidian at rumkin dot com
New email:
PHP Version: OS:

 

 [2011-06-08 18:01 UTC] 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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-06-08 18:08 UTC] scottmac@php.net
-Status: Open +Status: Duplicate
 [2011-06-08 18:08 UTC] scottmac@php.net
Was fixed in Bug #54137
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 01:01:30 2024 UTC