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

- Thread: https://externals.io/message/33000
- Original archive: https://news-web.php.net/php.internals/33000
- Started by dz@bitxtender.com on 2007-11-01T23:06:54+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #33000 — dz@bitxtender.com — 2007-11-01T23:06:54+00:00

URL: https://externals.io/message/33000#33000

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

---

## #33001 — dz@bitxtender.com — 2007-11-01T23:09:50+00:00

URL: https://externals.io/message/33000#33001 · In reply to: #33000

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#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

---

## #33016 — Sara Golemon — 2007-11-05T01:02:44+00:00

URL: https://externals.io/message/33000#33016 · In reply to: #33000

> 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
