|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-05-26 15:16 UTC] 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] => */* ) PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 15:00:01 2025 UTC |
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.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.