#41051 [Opn->Fbk]: Stream Context 'header' option ignored if value not of type array
| From: | tony2001@php.net | Date: | Wed, 11 Apr 2007 14:11:34 +0000 |
| Subject: | #41051 [Opn->Fbk]: Stream Context 'header' option ignored if value not of type array | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-111355@lists.php.net to get a copy of this message | ||
ID: 41051
Updated by: tony2001@php.net
Reported By: chris dot vigelius at gmx dot net
-Status: Open
+Status: Feedback
Bug Type: Streams related
Operating System: Linux (Ubuntu Edgy)
PHP Version: 5.2.1
New Comment:
Please disable --curl-wrappers and try again.
Previous Comments:
------------------------------------------------------------------------
[2007-04-11 12:36:07] chris dot vigelius at gmx dot net
Note: my php was compiled with '--with-curl' '--with-curlwrappers',
if that matters.
------------------------------------------------------------------------
[2007-04-11 12:28:14] 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)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=41051&edit=1