ID: 45092 Updated by: bj...@php.net Reported By: nweibley at gmail dot com -Status: To be documented +Status: Closed Bug Type: Streams related Operating System: Linux (Gentoo) PHP Version: 5.2.6 New Comment:
Docs updated Previous Comments: ------------------------------------------------------------------------ [2009-05-05 01:05:43] nweibley at gmail dot com Thanks for the update! ------------------------------------------------------------------------ [2009-05-05 00:34:47] j...@php.net As of PHP 5.9.10 you can pass either string or array (simple array, not any key => value pairs!) regardless if you used --with-curlwrappers option or not. ------------------------------------------------------------------------ [2008-05-26 15:34:59] nweibley at gmail dot com Ah, came to the solution. Line 332 of ext/curl/streams.c: if (Z_TYPE_PP(header) == IS_STRING) { Ergo, each element of the array passed as the value of the 'header' context option *must* be a string, not an associative key=>value pair. I'd propose this be more clearly documented or an additional conditional branch be added to ext/curl/streams.c to handle key=>value array pairs and especially a simple string as the header context option. This is the behavior when --with-curlwrappers is not used, and it seems highly logical that it would still stand with curlwrappers enabled. ------------------------------------------------------------------------ [2008-05-26 15:27:37] nweibley at gmail dot com Since line 324 of ext/curl/streams.c reads: if (SUCCESS == php_stream_context_get_option(context, "http", "header", &ctx_opt) && Z_TYPE_PP(ctx_opt) == IS_ARRAY) { I have changed my code to reflect passing an array as the value of 'header' in the context options. The problem still persists, however. ------------------------------------------------------------------------ [2008-05-26 15:16:09] nweibley at gmail dot com Description: ------------ Pretty simple; I'm trying to create a stream context which will send custom headers along with a simple HTTP GET request. It wasn't working so I created a second debug script to see what was up and found that PHP simply isn't including any of my custom headers. This *is not* a duplicate of bug #41051, I have tried that as well. Reproduce code: --------------- <?php //send.php $params = array('http' => array('method' => 'GET','header' => "Custom: woot")); $ctx = stream_context_create($params); $fp = fopen('http://localhost/recv.php', 'r', false, $ctx); print_r(stream_context_get_options($ctx)); print_r(stream_get_meta_data($fp)); echo stream_get_contents($fp); ?> <?php //recv.php print_r(apache_request_headers()); ?> Expected result: ---------------- Array ( [http] => Array ( [method] => GET [header] => Custom: woot ) ) Array ( [wrapper_data] => Array ( [headers] => Array ( ) [readbuf] => Resource id #4 ) [wrapper_type] => cURL [stream_type] => cURL [mode] => r [unread_bytes] => 0 [seekable] => [uri] => http://localhost/404.php [timed_out] => [blocked] => 1 [eof] => ) Array ( [User-Agent] => PHP/5.2.6-pl1-gentoo [Host] => localhost [Accept] => */* [Custom] => woot ) Actual result: -------------- Array ( [http] => Array ( [method] => GET [header] => Custom: woot ) ) Array ( [wrapper_data] => Array ( [headers] => Array ( ) [readbuf] => Resource id #4 ) [wrapper_type] => cURL [stream_type] => cURL [mode] => r [unread_bytes] => 0 [seekable] => [uri] => http://localhost/recv.php [timed_out] => [blocked] => 1 [eof] => ) Array ( [User-Agent] => PHP/5.2.6-pl1-gentoo [Host] => localhost [Accept] => */* ) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=45092&edit=1