From:             
Operating system: Ubuntu 11.04
PHP version:      5.3.6
Package:          HTTP related
Bug Type:         Bug
Bug description:POST requests send 4 extra bytes

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 bug report at http://bugs.php.net/bug.php?id=55010&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=55010&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=55010&r=trysnapshot53
Try a snapshot (trunk):              
http://bugs.php.net/fix.php?id=55010&r=trysnapshottrunk
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=55010&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=55010&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=55010&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=55010&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=55010&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=55010&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=55010&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=55010&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=55010&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=55010&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=55010&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=55010&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=55010&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=55010&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=55010&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=55010&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=55010&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=55010&r=mysqlcfg

Reply via email to