php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61119 HttpRequest::getHeaders() will return a flawed array
Submitted: 2012-02-17 09:45 UTC Modified: 2012-04-04 10:59 UTC
From: s dot kang at traviangames dot com Assigned: mike (profile)
Status: No Feedback Package: pecl_http (PECL)
PHP Version: Irrelevant OS: Ubuntu Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: s dot kang at traviangames dot com
New email:
PHP Version: OS:

 

 [2012-02-17 09:45 UTC] s dot kang at traviangames dot com
Description:
------------
Hi,

the HttpRequest::getHeaders() method returns an associative array, which cannot be accessed normally. See code sample.

The php -i output for pecl_http:


HTTP Support => enabled
Extension Version => 1.7.1
Registered Classes => HttpUtil, HttpMessage, HttpRequest, HttpRequestPool, HttpRequestDataShare, HttpDeflateStream, HttpInflateStream, HttpResponse, HttpQueryString
Output Handlers => ob_deflatehandler, ob_inflatehandler, ob_etaghandler
Stream Filters => http.chunked_decode, http.chunked_encode, http.deflate, http.inflate

Used Library => Compiled => Linked
libcurl => 7.21.3 => 7.21.3
libevent => 1.4 or greater => 1.4.12-stable
libz => 1.2.3.4 => 1.2.3.4
libmagic => disabled => disabled


Test script:
---------------
/* @var $req \HttpRequest */
$headers = (array)$req->getHeaders();
var_export($headers['Accept']); // Undefined index: Accept
array_key_exists('Accept', $headers); // false
$headers = unserialize(serialize($headers));
array_key_exists('Accept', $headers); // true

Expected result:
----------------
Script should display the contents of Accept header
e.g. array(0 => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8')
first array_key_exists should yield true

Actual result:
--------------
Undefined index: Accept
false


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-02-17 12:37 UTC] s dot kang at traviangames dot com
Additionally I noticed, that there was a problem when assigning the headers:

$headers = array(
  'X-Test' => array( 0 => 'test')
);
$req = new HttpRequest();
$req->setHeaders($headers);

So the headers were provided in a wrong way.
 [2012-02-17 12:43 UTC] s dot kang at traviangames dot com
After further investigation the wrongly provided headers are not the cause of the experienced bug.

$headers = array(
  'X-Test' => 'test'
);
$req = new HttpRequest();
$req->setHeaders($headers);
array_key_exists('X-Test', $req->getHeaders()); // false
 [2012-02-17 13:14 UTC] mike@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.


 [2012-02-17 13:14 UTC] mike@php.net
-Status: Open +Status: Feedback
 [2012-04-04 10:59 UTC] mike@php.net
-Status: Feedback +Status: No Feedback -Assigned To: +Assigned To: mike
 [2012-04-04 10:59 UTC] mike@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 13:01:31 2024 UTC