php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45092 header HTTP context option not being used (--with-curlwrappers)
Submitted: 2008-05-26 15:16 UTC Modified: 2009-05-05 07:58 UTC
From: nweibley at gmail dot com Assigned:
Status: Closed Package: Streams related
PHP Version: 5.2.6 OS: Linux (Gentoo)
Private report: No CVE-ID: None
 [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] => */*
)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-05-26 15:27 UTC] 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:34 UTC] 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.
 [2009-05-05 00:34 UTC] jani@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.
 [2009-05-05 01:05 UTC] nweibley at gmail dot com
Thanks for the update!
 [2009-05-05 07:58 UTC] bjori@php.net
Docs updated
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC