[Patch] http_fopen_wrapper.c and allowing any response code w/o warning

php.internals

David Zülke

18 years ago
Hi folks, I've recently played with CouchDB, which is a document database with a RESTful HTTP interface. I noticed, however, that there is no way to prevent PHP from throwing a warning on response codes other than 200, 206, 301, 302 and 303. Something like 201 Created throws a warning, for example. But I'm not sure if simply adding that one to the list is the proper way forward, as I imagine there are many situations when you just want to get the response content and look at the headers afterwards (w/ stream_get_meta_data). So I looked at the code and came up with this change for http_fopen_wrapper.c line 547 (http://lxr.php.net/source/php-src/ext/standard/http_fopen_wrapper.c#547 ): if ((options & STREAM_ONLY_GET_HEADERS) || (php_stream_context_get_option(context, "http", "ignore_errors", &tmpzval) == SUCCESS && Z_TYPE_PP(tmpzval) == IS_BOOL && Z_BVAL(retval))) { So when the option "ignore_errors" is set for HTTP on the context, no error will be thrown, and the response body is returned properly. Is that a reasonable idea? I'm not entirely sure about the "ignore_errors" name, maybe someone has a better suggestion. I'd be happy to supply a full patch, but I wanted to hear if anyone has thoughts on this first. Cheers, David

David Zülke

18 years ago
This is probably better: if (options & STREAM_ONLY_GET_HEADERS || (php_stream_context_get_option(context, "http", "ignore_errors", &tmpzval) == SUCCESS && Z_BVAL_PP(tmpzval))) { - David Am 02.11.2007 um 00:06 schrieb David Zülke:

Jared Williams

18 years ago
Yes, had fun with trying to use http php streams ... Imo, 2xx status codes should always be considered succesful. http://bugs.php.net/bug.php?id=36947 http://marc.info/?l=php-internals&m=111384113712112&w=2 J

David Coallier

18 years ago
On 11/2/07, Jared Williams <jared.williams1@ntlworld.com> wrote: > > Yes, had fun with trying to use http php streams ... Imo, 2xx status codes > should always be considered succesful. > I personally do not consider all of them to be "right" but I also think they should be cosnidered successful, since they are. > http://bugs.php.net/bug.php?id=36947 > > http://marc.info/?l=php-internals&m=111384113712112&w=2 > > J > > > -----Original Message----- > > From: David Zülke [mailto:dz@bitxtender.com] > > Sent: 01 November 2007 23:10 > > To: PHP Internals > > Subject: Re: [PHP-DEV] [Patch] http_fopen_wrapper.c and > > allowing any response code w/o warning > > > > This is probably better: > > > > if (options & STREAM_ONLY_GET_HEADERS || > > (php_stream_context_get_option(context, "http", "ignore_errors", > > &tmpzval) == SUCCESS && Z_BVAL_PP(tmpzval))) { > > > > > > - David > > > > > > Am 02.11.2007 um 00:06 schrieb David Zülke: > > > > > Hi folks, > > > > > > I've recently played with CouchDB, which is a document > > database with a > > > RESTful HTTP interface. > > > > > > I noticed, however, that there is no way to prevent PHP > > from throwing > > > a warning on response codes other than 200, 206, 301, 302 and 303. > > > > > > Something like 201 Created throws a warning, for example. > > > > > > But I'm not sure if simply adding that one to the list is > > the proper > > > way forward, as I imagine there are many situations when > > you just want > > > to get the response content and look at the headers afterwards (w/ > > > stream_get_meta_data). So I looked at the code and came up > > with this > > > change for http_fopen_wrapper.c line 547 > > > > > (http://lxr.php.net/source/php-src/ext/standard/http_fopen_wrapper.c#5 > > > 47 > > > ): > > > > > > if ((options & STREAM_ONLY_GET_HEADERS) || > > > (php_stream_context_get_option(context, "http", "ignore_errors", > > > &tmpzval) == SUCCESS && Z_TYPE_PP(tmpzval) == IS_BOOL && > > > Z_BVAL(retval))) { > > > > > > So when the option "ignore_errors" is set for HTTP on the > > context, no > > > error will be thrown, and the response body is returned properly. > > > > > > Is that a reasonable idea? I'm not entirely sure about the > > > "ignore_errors" name, maybe someone has a better suggestion. > > > > > > I'd be happy to supply a full patch, but I wanted to hear if anyone > > > has thoughts on this first. > > > > > > Cheers, > > > > > > David > > > > > > -- > > > PHP Internals - PHP Runtime Development Mailing List To > > unsubscribe, > > > visit: http://www.php.net/unsub.php > > > > > > > > > > -- > > PHP Internals - PHP Runtime Development Mailing List To > > unsubscribe, visit: http://www.php.net/unsub.php > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > -- David Coallier, Founder & Software Architect, Agora Production (http://agoraproduction.com) 51.42.06.70.18

Alexey Zakhlestin

18 years ago
On 11/2/07, Jared Williams <jared.williams1@ntlworld.com> wrote: > > Yes, had fun with trying to use http php streams ... Imo, 2xx status codes > should always be considered succesful. I believe, that there should be possibility to get even the document with 404th status (as the error-page might be valuable too). Streams have a nice api for notifications — that should be enough for error handling. No need to return false and give a warning (at least, when notifications are handled). -- Alexey Zakhlestin http://blog.milkfarmsoft.com/

Sara Golemon

18 years ago
> So I looked at the code and came up with this > change for http_fopen_wrapper.c line 547 > (http://lxr.php.net/source/php-src/ext/standard/http_fopen_wrapper.c#547): > > if ((options & STREAM_ONLY_GET_HEADERS) || > (php_stream_context_get_option(context, "http", "ignore_errors", > &tmpzval) == SUCCESS && Z_TYPE_PP(tmpzval) == IS_BOOL && Z_BVAL(retval))) { >
Cheers! http://news.php.net/php.cvs/46932 http://news.php.net/php.cvs/46933 -Sara