Req #63897 [Opn]: Custom http stream wrappers should be able to set $http_response_header

From: Date: Wed, 13 Oct 2021 17:56:51 +0000
Subject: Req #63897 [Opn]: Custom http stream wrappers should be able to set $http_response_header
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-237185@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=63897&edit=1 ID: 63897 Updated by: cmb@php.net Reported by: slangley at google dot com Summary: Custom http stream wrappers should be able to set $http_response_header Status: Open Type: Feature/Change Request Package: Streams related PHP Version: Irrelevant Block user comment: N Private report: N New Comment: See also <https://wiki.php.net/rfc/deprecations_php_8_1#predefined_variable_http_response_header>. Previous Comments: ------------------------------------------------------------------------ [2015-02-17 05:07:04] requinix@php.net There's been some discussion around removing the variable entirely. http://marc.info/?l=php-internals&m=141747294229627&w=2 ------------------------------------------------------------------------ [2015-02-17 04:56:29] 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. ------------------------------------------------------------------------ [2014-07-13 23:59:45] 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. ------------------------------------------------------------------------ [2014-07-13 13:02:03] datibbaw@php.net Can't you just use stream_get_meta_data() to get the same thing? ------------------------------------------------------------------------ [2013-01-04 00:57:08] 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. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=63897&edit=1

« previous php.bugs (#237185) next »