From 8c2a81a3728b23332ecb33a5f72727ea121dbeeb Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Wed, 8 Apr 2015 12:05:59 +0200 Subject: [PATCH] fix bug #69357 --- php_http_client_curl.c | 10 +++++++++- tests/bug69357.phpt | 41 +++++++++++++++++++++++++++++++++++++++++ tests/helper/upload.inc | 20 ++++++++++++++++++++ 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 tests/bug69357.phpt create mode 100644 tests/helper/upload.inc diff --git a/php_http_client_curl.c b/php_http_client_curl.c index 43a9337..9ebffa3 100644 --- a/php_http_client_curl.c +++ b/php_http_client_curl.c @@ -584,7 +584,14 @@ static php_http_message_t *php_http_curlm_responseparser(php_http_client_curl_ha response = php_http_message_init(NULL, 0, h->response.body TSRMLS_CC); php_http_header_parser_init(&parser TSRMLS_CC); - php_http_header_parser_parse(&parser, &h->response.headers, PHP_HTTP_HEADER_PARSER_CLEANUP, &response->hdrs, (php_http_info_callback_t) php_http_message_info_callback, (void *) &response); + while (h->response.headers.used) { + php_http_header_parser_state_t st = php_http_header_parser_parse(&parser, + &h->response.headers, PHP_HTTP_HEADER_PARSER_CLEANUP, &response->hdrs, + (php_http_info_callback_t) php_http_message_info_callback, (void *) &response); + if (PHP_HTTP_HEADER_PARSER_STATE_FAILURE == st) { + break; + } + } php_http_header_parser_dtor(&parser); /* move body to right message */ @@ -594,6 +601,7 @@ static php_http_message_t *php_http_curlm_responseparser(php_http_client_curl_ha while (ptr->parent) { ptr = ptr->parent; } + php_http_message_body_free(&response->body); response->body = ptr->body; ptr->body = NULL; } diff --git a/tests/bug69357.phpt b/tests/bug69357.phpt new file mode 100644 index 0000000..ac93baf --- /dev/null +++ b/tests/bug69357.phpt @@ -0,0 +1,41 @@ +--TEST-- +Bug #69357 (HTTP/1.1 100 Continue overriding subsequent 200 response code with PUT request) +--SKIPIF-- + +--FILE-- +append("foo") + ); + $c = new \http\Client; + $c->setOptions(["expect_100_timeout" => 0]); + $c->enqueue($r)->send(); + + var_dump($c->getResponse($r)->getInfo()); + var_dump($c->getResponse($r)->getHeaders()); +}); + +?> +===DONE=== +--EXPECTF-- +Test +string(15) "HTTP/1.1 200 OK" +array(4) { + ["Accept-Ranges"]=> + string(5) "bytes" + ["Etag"]=> + string(10) ""%x"" + ["X-Original-Transfer-Encoding"]=> + string(7) "chunked" + ["Content-Length"]=> + int(%d) +} +===DONE=== diff --git a/tests/helper/upload.inc b/tests/helper/upload.inc new file mode 100644 index 0000000..9502d2b --- /dev/null +++ b/tests/helper/upload.inc @@ -0,0 +1,20 @@ +getHeader("Expect") === "100-continue") { + $response = new http\Env\Response; + $response->setEnvRequest($request); + $response->setResponseCode(100); + $response->send($client); + } + + /* return the initial message as response body */ + $response = new http\Env\Response; + /* avoid OOM with $response->getBody()->append($request); */ + $request->toStream($response->getBody()->getResource()); + $response->send($client); +}); -- 2.30.2