PHP Bugs  
php.net | support | documentation | report a bug | advanced search | search howto | statistics | login

go to bug id or search bugs for  

Bug #41051 Stream Context 'header' option ignored if value not of type array
Submitted:11 Apr 2007 12:28pm UTC Modified: 19 Apr 2007 1:00am UTC
From:chris dot vigelius at gmx dot net Assigned to:
Status:No Feedback Category:Streams related
Version:5.2.1 OS:Linux (Ubuntu Edgy)
Votes:9 Avg. Score:3.7 ± 1.3 Reproduced:6 of 8 (75.0%)
Same Version:2 (33.3%) Same OS:2 (33.3%)
View/Vote Add Comment Developer Edit Submission

Have you experienced this issue?
Rate the importance of this bug to you:

[11 Apr 2007 12:28pm 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)
[11 Apr 2007 12:36pm UTC] chris dot vigelius at gmx dot net
Note: my php was compiled with '--with-curl' '--with-curlwrappers', 
if that matters.
[11 Apr 2007 2:11pm UTC] tony2001@php.net
Please disable --curl-wrappers and try again.
[19 Apr 2007 1:00am 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".

RSS feed | show source 

PHP Copyright © 2001-2009 The PHP Group
All rights reserved.
Last updated: Sat Nov 21 10:30:49 2009 UTC