#41051 [NEW]: Stream Context 'header' option ignored if value not of type array
| From: | chris dot vigelius at gmx dot net | Date: | Wed, 11 Apr 2007 12:28:14 +0000 |
| Subject: | #41051 [NEW]: Stream Context 'header' option ignored if value not of type array | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-111343@lists.php.net to get a copy of this message | ||
From: chris dot vigelius at gmx dot net
Operating system: Linux (Ubuntu Edgy)
PHP version: 5.2.1
PHP Bug Type: Streams related
Bug description: Stream Context 'header' option ignored if value not of type array
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 bug report at http://bugs.php.net/?id=41051&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=41051&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=41051&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=41051&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=41051&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=41051&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=41051&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=41051&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=41051&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=41051&r=support
Expected behavior: http://bugs.php.net/fix.php?id=41051&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=41051&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=41051&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=41051&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=41051&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=41051&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=41051&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=41051&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=41051&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=41051&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=41051&r=mysqlcfg