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 */
while (ptr->parent) {
ptr = ptr->parent;
}
+ php_http_message_body_free(&response->body);
response->body = ptr->body;
ptr->body = NULL;
}
--- /dev/null
+--TEST--
+Bug #69357 (HTTP/1.1 100 Continue overriding subsequent 200 response code with PUT request)
+--SKIPIF--
+<?php
+include "skipif.inc";
+skip_client_test();
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+include "helper/server.inc";
+
+server("upload.inc", function($port) {
+ $r = new \http\Client\Request("PUT", "http://localhost:$port/", [],
+ (new \http\Message\Body)->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===
--- /dev/null
+<?php
+
+include "server.inc";
+
+serve(function($client) {
+ $request = new http\Message($client, false);
+
+ if ($request->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);
+});