From 5787f91c55a7ebaeb34711d303cfc27f089f58b3 Mon Sep 17 00:00:00 2001 From: manuel Date: Sat, 6 Mar 2021 00:59:45 +0100 Subject: Fix #80838: HTTP wrapper waits for HTTP 1 response after HTTP 101 Don't wait for further responses after a HTTP 101 (Switching Protocols) response Closes GH-6730. --- NEWS | 2 ++ ext/standard/http_fopen_wrapper.c | 2 +- ext/standard/tests/http/bug80838.phpt | 41 +++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 ext/standard/tests/http/bug80838.phpt diff --git a/NEWS b/NEWS index afd2514519..751b79be69 100644 --- a/NEWS +++ b/NEWS @@ -28,6 +28,8 @@ PHP NEWS . Fixed bug #80771 (phpinfo(INFO_CREDITS) displays nothing in CLI). (cmb) . Fixed bug #78719 (http wrapper silently ignores long Location headers). (cmb) + . Fixed bug #80838 (HTTP wrapper waits for HTTP 1 response after HTTP 101). + (manuelm) 04 Mar 2021, php 7.4.16 diff --git a/ext/standard/http_fopen_wrapper.c b/ext/standard/http_fopen_wrapper.c index 4f702bf75f..4d918b21e6 100644 --- a/ext/standard/http_fopen_wrapper.c +++ b/ext/standard/http_fopen_wrapper.c @@ -680,7 +680,7 @@ finish: /* status codes of 1xx are "informational", and will be followed by a real response * e.g "100 Continue". RFC 7231 states that unexpected 1xx status MUST be parsed, * and MAY be ignored. As such, we need to skip ahead to the "real" status*/ - if (response_code >= 100 && response_code < 200) { + if (response_code >= 100 && response_code < 200 && response_code != 101) { /* consume lines until we find a line starting 'HTTP/1' */ while ( !php_stream_eof(stream) diff --git a/ext/standard/tests/http/bug80838.phpt b/ext/standard/tests/http/bug80838.phpt new file mode 100644 index 0000000000..2b81e042bb --- /dev/null +++ b/ext/standard/tests/http/bug80838.phpt @@ -0,0 +1,41 @@ +--TEST-- +Bug #80838 (HTTP wrapper waits for HTTP 1 response after HTTP 101) +--INI-- +allow_url_fopen=1 +--SKIPIF-- + +--FILE-- + [ + 'ignore_errors' => true + ], +]; + +$ctx = stream_context_create($options); + +$fd = fopen('http://127.0.0.1:12342/', 'rb', false, $ctx); +fclose($fd); +var_dump($http_response_header); + +http_server_kill($pid); + +?> +--EXPECT-- +array(3) { + [0]=> + string(32) "HTTP/1.1 101 Switching Protocols" + [1]=> + string(15) "Header1: Value1" + [2]=> + string(15) "Header2: Value2" +} -- cgit v1.2.1