php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41051 Stream Context 'header' option ignored if value not of type array
Submitted: 2007-04-11 12:28 UTC Modified: 2007-04-19 01:00 UTC
Votes:17
Avg. Score:3.8 ± 1.2
Reproduced:10 of 13 (76.9%)
Same Version:4 (40.0%)
Same OS:3 (30.0%)
From: chris dot vigelius at gmx dot net Assigned:
Status: No Feedback Package: Streams related
PHP Version: 5.2.1 OS: Linux (Ubuntu Edgy)
Private report: No CVE-ID:
Have you experienced this issue?
Rate the importance of this bug to you:

 [2007-04-11 12:28 UTC] chris dot vigelius at gmx dot net
Description:
------------
the http wrapper ignores 'header' option in stream_create_context( ) if the value is not given as a simple array; neither a string nor a map (e.g. array('X-My-Header' => 'test')) will cause the additional headers to be sent.

Reproduce code:
---------------
// given as string, the header will not be sent
$url = 'http://protectedstuff.com';
$auth = base64_encode('user:password');
$header = "Authorization: Basic $auth";
$opts = array( 'http' => array ('method'=>'GET',
                                'header'=>$header));
$ctx = stream_context_create($opts);
file_get_contents($url,false,$ctx);

// only if $header is an array, it will be sent
$url = 'http://protectedstuff.com';
$auth = base64_encode('user:password');
$header = array("Authorization: Basic $auth");
$opts = array( 'http' => array ('method'=>'GET',
                                'header'=>$header));
$ctx = stream_context_create($opts);
file_get_contents($url,false,$ctx);

Expected result:
----------------
// In BOTH cases, one would expect the following headers to be sent 
// with the request

GET / HTTP/1.1

User-Agent: PHP/5.2.1

Host: protectedstuff.com

Pragma: no-cache

Accept: */*

Authorization: Basic dXNlcjpwYXNzd29yZA=




Actual result:
--------------
// The first request is sent with the following headers instead

GET / HTTP/1.1

User-Agent: PHP/5.2.1

Host: protectedstuff.com

Pragma: no-cache

Accept: */*



(note that there is no 'Authorization:' header)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-04-11 12:36 UTC] chris dot vigelius at gmx dot net
Note: my php was compiled with '--with-curl' '--with-curlwrappers', 
if that matters.
 [2007-04-11 14:11 UTC] tony2001@php.net
Please disable --curl-wrappers and try again.
 [2007-04-19 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Fri Apr 18 08:02:55 2014 UTC