php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #63897 Custom http stream wrappers should be able to set $http_response_header
Submitted: 2013-01-04 00:57 UTC Modified: 2021-10-13 17:56 UTC
Votes:3
Avg. Score:4.3 ± 0.9
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:1 (33.3%)
From: slangley at google dot com Assigned:
Status: Open Package: Streams related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: slangley at google dot com
New email:
PHP Version: OS:

 

 [2013-01-04 00:57 UTC] slangley at google dot com
Description:
------------
It is possible to write custom http/https stream wrappers in 'native' php, however 
it is impossible to get them to work correctly because of the magic variable 
$http_response_header.

From http://php.net/manual/en/reserved.variables.httpresponseheader.php 
"$http_response_header will be created in the local scope." There is no way that I 
can determine that allows a PHP script to create this variable "in the local 
scope".

Perhaps it would be possible to provide a method "set_http_response_header" that 
will allow this variable to be set from a script.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-07-13 13:02 UTC] datibbaw@php.net
Can't you just use stream_get_meta_data() to get the same thing?
 [2014-07-13 23:59 UTC] slangley at google dot com
The idea is to be able to replace the built-in http(s) stream wrappers with custom versions and have that work with *existing* applications, a heap of which already use $http_response_header. If you can't replicate the environment 100% with the custom wrapper then you're stuck.
 [2015-02-17 04:56 UTC] php dot net at tylercollier dot com
I'm experiencing this issue too. I'm on PHP 5.3 and 5.4 on Ubuntu 12.04 and Mac OS X 10.9 and 10.10.

I'm working with the PHP-VCR project, which seems like as good a place as any where being able to replicate the ability to set $http_response_header makes sense. See https://github.com/php-vcr/php-vcr/issues/96.

I looked through the C source code. There are only two places where a local variable is forced like this (the other is php_errormsg). This one is at https://github.com/php/php-src/blob/85aab94d8105f2fa18650f59399dd5d8ddce3668/ext/standard/http_fopen_wrapper.c#L669. It calls a method named zend_set_local_var_str, which appears to walk up the stack until it's not in Zend code, in which case, even if you could trigger it, it would set the local variable in your method, not where you intercepted the http stream, as desired.

I'm not sure why a local variable was chosen as the way to get headers. Why not something like error_get_last()? (I confess to not using that much, but it seems like a better method of encapsulation and thus avoiding the problem(s) we have here. I don't see a way to SET the last error though.) I think that allowing a http_header_get_last() as an additional way of retrieving the last http header could be done by the PHP team.
 [2015-02-17 05:07 UTC] requinix@php.net
There's been some discussion around removing the variable entirely.
http://marc.info/?l=php-internals&m=141747294229627&w=2
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 18:01:29 2024 UTC