Skip to content

Commit 5787f91

Browse files
manuelmcmb69
authored andcommitted
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.
1 parent 8fc0bdf commit 5787f91

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ PHP NEWS
2828
. Fixed bug #80771 (phpinfo(INFO_CREDITS) displays nothing in CLI). (cmb)
2929
. Fixed bug #78719 (http wrapper silently ignores long Location headers).
3030
(cmb)
31+
. Fixed bug #80838 (HTTP wrapper waits for HTTP 1 response after HTTP 101).
32+
(manuelm)
3133

3234
04 Mar 2021, php 7.4.16
3335

ext/standard/http_fopen_wrapper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
680680
/* status codes of 1xx are "informational", and will be followed by a real response
681681
* e.g "100 Continue". RFC 7231 states that unexpected 1xx status MUST be parsed,
682682
* and MAY be ignored. As such, we need to skip ahead to the "real" status*/
683-
if (response_code >= 100 && response_code < 200) {
683+
if (response_code >= 100 && response_code < 200 && response_code != 101) {
684684
/* consume lines until we find a line starting 'HTTP/1' */
685685
while (
686686
!php_stream_eof(stream)

ext/standard/tests/http/bug80838.phpt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
--TEST--
2+
Bug #80838 (HTTP wrapper waits for HTTP 1 response after HTTP 101)
3+
--INI--
4+
allow_url_fopen=1
5+
--SKIPIF--
6+
<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:12342'); ?>
7+
--FILE--
8+
<?php
9+
require 'server.inc';
10+
11+
$responses = [
12+
"data://text/plain,HTTP/1.1 101 Switching Protocols\r\nHeader1: Value1\r\nHeader2: Value2\r\n\r\n"
13+
. "Hello from another protocol"
14+
];
15+
16+
$pid = http_server('tcp://127.0.0.1:12342', $responses);
17+
18+
$options = [
19+
'http' => [
20+
'ignore_errors' => true
21+
],
22+
];
23+
24+
$ctx = stream_context_create($options);
25+
26+
$fd = fopen('http://127.0.0.1:12342/', 'rb', false, $ctx);
27+
fclose($fd);
28+
var_dump($http_response_header);
29+
30+
http_server_kill($pid);
31+
32+
?>
33+
--EXPECT--
34+
array(3) {
35+
[0]=>
36+
string(32) "HTTP/1.1 101 Switching Protocols"
37+
[1]=>
38+
string(15) "Header1: Value1"
39+
[2]=>
40+
string(15) "Header2: Value2"
41+
}

0 commit comments

Comments
 (0)