Hi Arnaud,
Thanks for the tip, please find patch attached.
Best,
Tjerk
On Fri, May 15, 2009 at 10:58 PM, Arnaud Le Blanc <[email protected]> wrote:
> Hi,
>
> On Fri, 2009-05-15 at 22:16 +0800, Tjerk Anne Meesters wrote:
>> Hi,
>>
>> I've been extending the pecl/oauth code to work with php stream
>> wrappers in cases whereby curl is not enabled, but I've hit a snag.
>>
>> The documentation states that enabling the "ignore_errors" flag will
>> fetch the content even on failure status codes. At the same time,
>> setting "max_redirects" to <= 1 indicates that no redirects will be
>> followed.
>>
>> It does not state that setting "max_redirects" <= 1 would actually
>> trigger an error, though in the code it returns (php_stream *)NULL
>> making it impossible to even get the headers out of the wrapperdata
>> hash unless STREAM_ONLY_GET_HEADERS is used.
>>
>> So, either setting "max_redirects" <= 1 should not throw NULL back
>> into the caller code or "ignore_error" behaviour should be extended to
>> prevent that from happening.
>>
>> My attached patch favours to fix the latter, since the "ignore_errors"
>> is a relatively new flag. Hope it will be accepted for the 5.3
>> release.
>
> max_redirects's purpose is to avoid infinite loops, etc. Stream
> functions are expected to return an error in case the limit is exceeded.
> If they do not, scripts will get an empty body without noticing the
> error (changing this may break existing scripts).
>
> ignore_errors is a new flag, it forces scripts to check HTTP status code
> (so that scripts will notice non-200 ones) and changing it to ignore
> redirects when max_redirects is exceeded seems to be a good solution.
>
>>
>> (not sure whether attachments will be allowed ... give me a ping if it
>> doesn't make it through)
>
> The list accepts only text/plain attachments (try renaming your patch
> to .txt).
>
>
> Regards,
>
> Arnaud
>
>
>
--
--
Tjerk
Index: http_fopen_wrapper.c
===================================================================
RCS file: /repository/php-src/ext/standard/http_fopen_wrapper.c,v
retrieving revision 1.99.2.12.2.9.2.16
diff -u -r1.99.2.12.2.9.2.16 http_fopen_wrapper.c
--- http_fopen_wrapper.c 14 May 2009 13:36:56 -0000
1.99.2.12.2.9.2.16
+++ http_fopen_wrapper.c 15 May 2009 13:31:18 -0000
@@ -104,7 +104,7 @@
size_t chunk_size = 0, file_size = 0;
int eol_detect = 0;
char *transport_string, *errstr = NULL;
- int transport_len, have_header = 0, request_fulluri = 0;
+ int transport_len, have_header = 0, request_fulluri = 0, ignore_errors
= 0;
char *protocol_version = NULL;
int protocol_version_len = 3; /* Default: "1.0" */
struct timeval timeout;
@@ -557,9 +557,11 @@
} else {
response_code = 0;
}
+ if (context &&
SUCCESS==php_stream_context_get_option(context, "http", "ignore_errors",
&tmpzval)) {
+ ignore_errors = zend_is_true(*tmpzval);
+ }
/* when we request only the header, don't fail even on
error codes */
- if ((options & STREAM_ONLY_GET_HEADERS) ||
- (context &&
php_stream_context_get_option(context, "http", "ignore_errors", &tmpzval) ==
SUCCESS && zend_is_true(*tmpzval)) ) {
+ if ((options & STREAM_ONLY_GET_HEADERS) ||
ignore_errors) {
reqok = 1;
}
/* all status codes in the 2xx range are defined by the
specification as successful;
@@ -656,7 +658,7 @@
}
if (!reqok || location[0] != '\0') {
- if (options & STREAM_ONLY_GET_HEADERS && redirect_max <= 1) {
+ if (((options & STREAM_ONLY_GET_HEADERS) || ignore_errors) &&
redirect_max <= 1) {
goto out;
}
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php