From 93a00e987cace536d8e60797a2f447c351965c98 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Thu, 9 Sep 2010 12:47:16 +0000 Subject: [PATCH] * if curl sees a 3xx code, a Location header and a Connection:close header it decides not to read the response body. --- php_http_request.c | 6 ++++-- php_http_request.h | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/php_http_request.c b/php_http_request.c index d6d9358..90b0f31 100644 --- a/php_http_request.c +++ b/php_http_request.c @@ -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; diff --git a/php_http_request.h b/php_http_request.h index 5432715..a81199e 100644 --- a/php_http_request.h +++ b/php_http_request.h @@ -15,6 +15,8 @@ #ifndef PHP_HTTP_REQUEST_H #define PHP_HTTP_REQUEST_H +#include + #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 { -- 2.30.2