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:29
Avg. Score:3.5 ± 1.3
Reproduced:14 of 20 (70.0%)
Same Version:4 (28.6%)
Same OS:4 (28.6%)
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: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: chris dot vigelius at gmx dot net
New email:
PHP Version: OS:

 

 [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

matrix75 (last revision 2016-07-27 20:27 UTC by ilyeshaji at gmail dot com)

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Sun Nov 24 15:01:36 2024 UTC