* if curl sees a 3xx code, a Location header and a Connection:close header it decides...
authorMichael Wallner <mike@php.net>
Thu, 9 Sep 2010 12:47:16 +0000 (12:47 +0000)
committerMichael Wallner <mike@php.net>
Thu, 9 Sep 2010 12:47:16 +0000 (12:47 +0000)
php_http_request.c
php_http_request.h

index d6d93587eaff4879b3e9857b9c6bd359d02c796e..90b0f31079019fe5cda31bdef0110ef7f492e297 100644 (file)
@@ -597,7 +597,7 @@ PHP_HTTP_API STATUS php_http_request_prepare(php_http_request_t *request, HashTa
        /* redirects, defaults to 0 */
        if ((zoption = php_http_request_option(request, options, ZEND_STRS("redirect"), IS_LONG))) {
                PHP_HTTP_CURL_OPT(CURLOPT_FOLLOWLOCATION, Z_LVAL_P(zoption) ? 1L : 0L);
-               PHP_HTTP_CURL_OPT(CURLOPT_MAXREDIRS, Z_LVAL_P(zoption));
+               PHP_HTTP_CURL_OPT(CURLOPT_MAXREDIRS, request->_cache.redirects = Z_LVAL_P(zoption));
                if ((zoption = php_http_request_option(request, options, ZEND_STRS("unrestrictedauth"), IS_BOOL))) {
                        PHP_HTTP_CURL_OPT(CURLOPT_UNRESTRICTED_AUTH, Z_LVAL_P(zoption));
                }
@@ -608,6 +608,8 @@ PHP_HTTP_API STATUS php_http_request_prepare(php_http_request_t *request, HashTa
                        PHP_HTTP_CURL_OPT(CURLOPT_POST301, Z_BVAL_P(zoption) ? 1L : 0L);
 #endif
                }
+       } else {
+               request->_cache.redirects = 0;
        }
        
        /* retries, defaults to 0 */
@@ -1019,7 +1021,7 @@ static int php_http_curl_raw_callback(CURL *ch, curl_infotype type, char *data,
                case CURLINFO_HEADER_OUT:
                case CURLINFO_DATA_OUT:
                        php_http_buffer_append(request->parser.buf, data, length);
-                       if (PHP_HTTP_MESSAGE_PARSER_STATE_FAILURE == php_http_message_parser_parse(request->parser.ctx, request->parser.buf, 0, &request->parser.msg)) {
+                       if (PHP_HTTP_MESSAGE_PARSER_STATE_FAILURE == php_http_message_parser_parse(request->parser.ctx, request->parser.buf, request->_cache.redirects?PHP_HTTP_MESSAGE_PARSER_EMPTY_REDIRECTS:0, &request->parser.msg)) {
                                return -1;
                        }
                        break;
index 543271563b215c41fa4cbaaed17add2949c2839d..a81199e62854f282b50ba9697b39a6bf29ace8bb 100644 (file)
@@ -15,6 +15,8 @@
 #ifndef PHP_HTTP_REQUEST_H
 #define PHP_HTTP_REQUEST_H
 
+#include <curl/curl.h>
+
 #include "php_http_request_method.h"
 #include "php_http_request_pool.h"
 
@@ -46,6 +48,7 @@ typedef struct php_http_request {
                php_http_buffer_t cookies;
                HashTable options;
                struct curl_slist *headers;
+               long redirects;
        } _cache;
        
        struct {