diff options
author | Rowan Tommins <git@rwec.co.uk> | 2020-06-11 19:05:00 +0100 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2020-08-03 16:30:09 +0200 |
commit | f9f769d4b9af367af864d35cf09dca5b08da2046 (patch) | |
tree | 67a8404011e152302460962f980c68e36e932f3f | |
parent | 9b975fe98e88c3fd5c41fe6b209b715cf190887a (diff) | |
download | php-git-f9f769d4b9af367af864d35cf09dca5b08da2046.tar.gz |
Make http stream wrapper advertise HTTP/1.1 by default
In practice, we always act as an HTTP/1.1 client, for compatibility
with servers which ignore protocol version. Sending the version in
the request will avoid problems with servers which don't ignore it.
HTTP/1.0 can still be forced using a stream context option.
Closes GH-5899.
-rw-r--r-- | UPGRADING | 8 | ||||
-rw-r--r-- | ext/standard/http_fopen_wrapper.c | 2 | ||||
-rw-r--r-- | ext/standard/tests/http/bug38802.phpt | 48 | ||||
-rw-r--r-- | ext/standard/tests/http/bug48929.phpt | 6 | ||||
-rw-r--r-- | ext/standard/tests/http/bug53198.phpt | 6 | ||||
-rw-r--r-- | ext/standard/tests/http/bug61548.phpt | 24 | ||||
-rw-r--r-- | ext/standard/tests/http/bug67430.phpt | 6 | ||||
-rw-r--r-- | ext/standard/tests/http/bug79265.phpt | 4 | ||||
-rw-r--r-- | ext/standard/tests/http/bug79265_2.phpt | 4 | ||||
-rw-r--r-- | ext/standard/tests/http/ignore_errors.phpt | 28 | ||||
-rw-r--r-- | sapi/cli/tests/bug69655.phpt | 6 | ||||
-rw-r--r-- | sapi/cli/tests/bug70264.phpt | 4 |
12 files changed, 77 insertions, 69 deletions
@@ -558,6 +558,14 @@ PHP 8.0 UPGRADE NOTES accept parameters by reference will now warn if a callback with reference parameters is used. Examples include array_filter() and array_reduce(). This was already the case for most, but not all, functions previously. + . The HTTP stream wrapper as used by functions like file_get_contents() + now advertises HTTP/1.1 rather than HTTP/1.0 by default. This does not + change the behaviour of the client, but may cause servers to respond + differently. To retain the old behaviour, set the 'protocol_version' + stream context option, e.g. + + $ctx = stream_context_create(['http' => ['protocol_version' => '1.0']]); + echo file_get_contents('http://example.org', false, $ctx); - Sysvmsg: . msg_get_queue() will now return an SysvMessageQueue object rather than a diff --git a/ext/standard/http_fopen_wrapper.c b/ext/standard/http_fopen_wrapper.c index ae9b915101..ac57c55efb 100644 --- a/ext/standard/http_fopen_wrapper.c +++ b/ext/standard/http_fopen_wrapper.c @@ -419,7 +419,7 @@ finish: smart_str_appends(&req_buf, "\r\n"); efree(protocol_version); } else { - smart_str_appends(&req_buf, " HTTP/1.0\r\n"); + smart_str_appends(&req_buf, " HTTP/1.1\r\n"); } if (context && (tmpzval = php_stream_context_get_option(context, "http", "header")) != NULL) { diff --git a/ext/standard/tests/http/bug38802.phpt b/ext/standard/tests/http/bug38802.phpt index 77fa16b5e4..dc00a834c1 100644 --- a/ext/standard/tests/http/bug38802.phpt +++ b/ext/standard/tests/http/bug38802.phpt @@ -13,10 +13,10 @@ function do_test($context_options) { $context = stream_context_create(array('http' => $context_options)); $responses = array( - "data://text/plain,HTTP/1.0 302 Moved Temporarily\r\nLocation: http://127.0.0.1:12342/foo/bar2\r\n\r\n1", - "data://text/plain,HTTP/1.0 301 Moved Permanently\r\nLocation: http://127.0.0.1:12342/foo/bar3\r\n\r\n", - "data://text/plain,HTTP/1.0 302 Moved Temporarily\r\nLocation: http://127.0.0.1:12342/foo/bar4\r\n\r\n3", - "data://text/plain,HTTP/1.0 200 OK\r\n\r\ndone.", + "data://text/plain,HTTP/1.1 302 Moved Temporarily\r\nLocation: http://127.0.0.1:12342/foo/bar2\r\n\r\n1", + "data://text/plain,HTTP/1.1 301 Moved Permanently\r\nLocation: http://127.0.0.1:12342/foo/bar3\r\n\r\n", + "data://text/plain,HTTP/1.1 302 Moved Temporarily\r\nLocation: http://127.0.0.1:12342/foo/bar4\r\n\r\n3", + "data://text/plain,HTTP/1.1 200 OK\r\n\r\ndone.", ); $pid = http_server("tcp://127.0.0.1:12342", $responses, $output); @@ -71,34 +71,34 @@ do_test(array('max_redirects' => 2, 'ignore_errors' => 1), 2); resource(%d) of type (stream) array(7) { [0]=> - string(30) "HTTP/1.0 302 Moved Temporarily" + string(30) "HTTP/1.1 302 Moved Temporarily" [1]=> string(41) "Location: http://127.0.0.1:12342/foo/bar2" [2]=> - string(30) "HTTP/1.0 301 Moved Permanently" + string(30) "HTTP/1.1 301 Moved Permanently" [3]=> string(41) "Location: http://127.0.0.1:12342/foo/bar3" [4]=> - string(30) "HTTP/1.0 302 Moved Temporarily" + string(30) "HTTP/1.1 302 Moved Temporarily" [5]=> string(41) "Location: http://127.0.0.1:12342/foo/bar4" [6]=> - string(15) "HTTP/1.0 200 OK" + string(15) "HTTP/1.1 200 OK" } string(5) "done." -string(%d) "GET /foo/bar HTTP/1.0 +string(%d) "GET /foo/bar HTTP/1.1 Host: 127.0.0.1:12342 Connection: close -GET /foo/bar2 HTTP/1.0 +GET /foo/bar2 HTTP/1.1 Host: 127.0.0.1:12342 Connection: close -GET /foo/bar3 HTTP/1.0 +GET /foo/bar3 HTTP/1.1 Host: 127.0.0.1:12342 Connection: close -GET /foo/bar4 HTTP/1.0 +GET /foo/bar4 HTTP/1.1 Host: 127.0.0.1:12342 Connection: close @@ -107,11 +107,11 @@ Connection: close Warning: fopen(http://127.0.0.1:12342/foo/bar): Failed to open stream: Redirection limit reached, aborting in %s bool(false) -string(%d) "GET /foo/bar HTTP/1.0 +string(%d) "GET /foo/bar HTTP/1.1 Host: 127.0.0.1:12342 Connection: close -GET /foo/bar2 HTTP/1.0 +GET /foo/bar2 HTTP/1.1 Host: 127.0.0.1:12342 Connection: close @@ -120,7 +120,7 @@ Connection: close Warning: fopen(http://127.0.0.1:12342/foo/bar): Failed to open stream: Redirection limit reached, aborting in %s bool(false) -string(%d) "GET /foo/bar HTTP/1.0 +string(%d) "GET /foo/bar HTTP/1.1 Host: 127.0.0.1:12342 Connection: close @@ -129,7 +129,7 @@ Connection: close Warning: fopen(http://127.0.0.1:12342/foo/bar): Failed to open stream: Redirection limit reached, aborting in %s bool(false) -string(%d) "GET /foo/bar HTTP/1.0 +string(%d) "GET /foo/bar HTTP/1.1 Host: 127.0.0.1:12342 Connection: close @@ -138,12 +138,12 @@ Connection: close resource(%d) of type (stream) array(2) { [0]=> - string(30) "HTTP/1.0 302 Moved Temporarily" + string(30) "HTTP/1.1 302 Moved Temporarily" [1]=> string(41) "Location: http://127.0.0.1:12342/foo/bar2" } string(1) "1" -string(%d) "GET /foo/bar HTTP/1.0 +string(%d) "GET /foo/bar HTTP/1.1 Host: 127.0.0.1:12342 Connection: close @@ -152,12 +152,12 @@ Connection: close resource(%d) of type (stream) array(2) { [0]=> - string(30) "HTTP/1.0 302 Moved Temporarily" + string(30) "HTTP/1.1 302 Moved Temporarily" [1]=> string(41) "Location: http://127.0.0.1:12342/foo/bar2" } string(1) "1" -string(%d) "GET /foo/bar HTTP/1.0 +string(%d) "GET /foo/bar HTTP/1.1 Host: 127.0.0.1:12342 Connection: close @@ -166,20 +166,20 @@ Connection: close resource(%d) of type (stream) array(4) { [0]=> - string(30) "HTTP/1.0 302 Moved Temporarily" + string(30) "HTTP/1.1 302 Moved Temporarily" [1]=> string(41) "Location: http://127.0.0.1:12342/foo/bar2" [2]=> - string(30) "HTTP/1.0 301 Moved Permanently" + string(30) "HTTP/1.1 301 Moved Permanently" [3]=> string(41) "Location: http://127.0.0.1:12342/foo/bar3" } string(0) "" -string(%d) "GET /foo/bar HTTP/1.0 +string(%d) "GET /foo/bar HTTP/1.1 Host: 127.0.0.1:12342 Connection: close -GET /foo/bar2 HTTP/1.0 +GET /foo/bar2 HTTP/1.1 Host: 127.0.0.1:12342 Connection: close diff --git a/ext/standard/tests/http/bug48929.phpt b/ext/standard/tests/http/bug48929.phpt index 9a769d8674..fad8775b6a 100644 --- a/ext/standard/tests/http/bug48929.phpt +++ b/ext/standard/tests/http/bug48929.phpt @@ -13,7 +13,7 @@ function do_test($context_options) { $context = stream_context_create(array('http' => $context_options)); $responses = array( - "data://text/plain,HTTP/1.0 200 OK\r\n\r\n", + "data://text/plain,HTTP/1.1 200 OK\r\n\r\n", ); $pid = http_server("tcp://127.0.0.1:12342", $responses, $output); @@ -41,7 +41,7 @@ do_test(array('header' => "X-Foo: bar\r\nContent-Type: text/plain", 'method' => ?> --EXPECTF-- -- Test: requests with 'header' as array -- -string(%d) "POST / HTTP/1.0 +string(%d) "POST / HTTP/1.1 Host: 127.0.0.1:12342 Connection: close Content-Length: 4 @@ -50,7 +50,7 @@ Content-Type: text/plain ohai" -- Test: requests with 'header' as string -- -string(%d) "POST / HTTP/1.0 +string(%d) "POST / HTTP/1.1 Host: 127.0.0.1:12342 Connection: close Content-Length: 4 diff --git a/ext/standard/tests/http/bug53198.phpt b/ext/standard/tests/http/bug53198.phpt index add07c3f47..da2a4cf15f 100644 --- a/ext/standard/tests/http/bug53198.phpt +++ b/ext/standard/tests/http/bug53198.phpt @@ -12,7 +12,7 @@ require 'server.inc'; function do_test() { $responses = array( - "data://text/plain,HTTP/1.0 200 OK\r\n\r\n", + "data://text/plain,HTTP/1.1 200 OK\r\n\r\n", ); $pid = http_server("tcp://127.0.0.1:12342", $responses, $output); @@ -43,14 +43,14 @@ do_test(); ?> --EXPECTF-- -- Test: leave default -- -string(%d) "GET / HTTP/1.0 +string(%d) "GET / HTTP/1.1 From: teste@teste.pt Host: 127.0.0.1:12342 Connection: close " -- Test: after ini_set -- -string(%d) "GET / HTTP/1.0 +string(%d) "GET / HTTP/1.1 From: junk@junk.com Host: 127.0.0.1:12342 Connection: close diff --git a/ext/standard/tests/http/bug61548.phpt b/ext/standard/tests/http/bug61548.phpt index 04ea55341b..24e709bf36 100644 --- a/ext/standard/tests/http/bug61548.phpt +++ b/ext/standard/tests/http/bug61548.phpt @@ -42,35 +42,35 @@ do_test("First:1\nContent-type:text/plain\nSecond:2\nThird:"); ?> Done --EXPECT-- -POST / HTTP/1.0 +POST / HTTP/1.1 Host: 127.0.0.1:12342 Connection: close First:1 Second:2 Content-type: text/plain -GET /foo HTTP/1.0 +GET /foo HTTP/1.1 Host: 127.0.0.1:12342 Connection: close First:1 Second:2 -POST / HTTP/1.0 +POST / HTTP/1.1 Host: 127.0.0.1:12342 Connection: close First:1 Second:2 Content-type: text/plain -GET /foo HTTP/1.0 +GET /foo HTTP/1.1 Host: 127.0.0.1:12342 Connection: close First:1 Second:2 -POST / HTTP/1.0 +POST / HTTP/1.1 Host: 127.0.0.1:12342 Connection: close First:1 @@ -78,40 +78,40 @@ Second:2 Content-type: text/plain Third: -GET /foo HTTP/1.0 +GET /foo HTTP/1.1 Host: 127.0.0.1:12342 Connection: close First:1 Second:2 Third: -POST / HTTP/1.0 +POST / HTTP/1.1 Host: 127.0.0.1:12342 Connection: close First:1 Content-type:text/plain Second:2 -GET /foo HTTP/1.0 +GET /foo HTTP/1.1 Host: 127.0.0.1:12342 Connection: close First:1 Second:2 -POST / HTTP/1.0 +POST / HTTP/1.1 Host: 127.0.0.1:12342 Connection: close First:1 Content-type:text/plain Second:2 -GET /foo HTTP/1.0 +GET /foo HTTP/1.1 Host: 127.0.0.1:12342 Connection: close First:1 Second:2 -POST / HTTP/1.0 +POST / HTTP/1.1 Host: 127.0.0.1:12342 Connection: close First:1 @@ -119,7 +119,7 @@ Content-type:text/plain Second:2 Third: -GET /foo HTTP/1.0 +GET /foo HTTP/1.1 Host: 127.0.0.1:12342 Connection: close First:1 diff --git a/ext/standard/tests/http/bug67430.phpt b/ext/standard/tests/http/bug67430.phpt index a563951cd8..cf8db65cf1 100644 --- a/ext/standard/tests/http/bug67430.phpt +++ b/ext/standard/tests/http/bug67430.phpt @@ -37,15 +37,15 @@ do_test(false); ?> Done --EXPECT-- -POST / HTTP/1.0 +POST / HTTP/1.1 Host: 127.0.0.1:12342 Connection: close -GET /foo HTTP/1.0 +GET /foo HTTP/1.1 Host: 127.0.0.1:12342 Connection: close -POST / HTTP/1.0 +POST / HTTP/1.1 Host: 127.0.0.1:12342 Connection: close diff --git a/ext/standard/tests/http/bug79265.phpt b/ext/standard/tests/http/bug79265.phpt index 4848991bd0..25efdd089a 100644 --- a/ext/standard/tests/http/bug79265.phpt +++ b/ext/standard/tests/http/bug79265.phpt @@ -9,7 +9,7 @@ allow_url_fopen=1 require 'server.inc'; $responses = array( - "data://text/plain,HTTP/1.0 200 OK\r\n\r\n", + "data://text/plain,HTTP/1.1 200 OK\r\n\r\n", ); $pid = http_server("tcp://127.0.0.1:12342", $responses, $output); @@ -32,7 +32,7 @@ http_server_kill($pid); ?> --EXPECT-- -GET / HTTP/1.0 +GET / HTTP/1.1 Connection: close RandomHeader: localhost:8080 Cookie: foo=bar diff --git a/ext/standard/tests/http/bug79265_2.phpt b/ext/standard/tests/http/bug79265_2.phpt index d2f5bc1e38..0cdde10501 100644 --- a/ext/standard/tests/http/bug79265_2.phpt +++ b/ext/standard/tests/http/bug79265_2.phpt @@ -9,7 +9,7 @@ allow_url_fopen=1 require 'server.inc'; $responses = array( - "data://text/plain,HTTP/1.0 200 OK\r\n\r\n", + "data://text/plain,HTTP/1.1 200 OK\r\n\r\n", ); $pid = http_server("tcp://127.0.0.1:12342", $responses, $output); @@ -31,7 +31,7 @@ http_server_kill($pid); ?> --EXPECT-- -GET / HTTP/1.0 +GET / HTTP/1.1 Host: 127.0.0.1:12342 Connection: close RandomHeader: host:8080 diff --git a/ext/standard/tests/http/ignore_errors.phpt b/ext/standard/tests/http/ignore_errors.phpt index 38a1cf6985..436fceeef9 100644 --- a/ext/standard/tests/http/ignore_errors.phpt +++ b/ext/standard/tests/http/ignore_errors.phpt @@ -13,8 +13,8 @@ function do_test($context_options) { $context = stream_context_create(array('http' => $context_options)); $responses = array( - "data://text/plain,HTTP/1.0 200 Ok\r\nX-Foo: bar\r\n\r\n1", - "data://text/plain,HTTP/1.0 404 Not found\r\nX-bar: baz\r\n\r\n2", + "data://text/plain,HTTP/1.1 200 Ok\r\nX-Foo: bar\r\n\r\n1", + "data://text/plain,HTTP/1.1 404 Not found\r\nX-bar: baz\r\n\r\n2", ); $pid = http_server("tcp://127.0.0.1:12342", $responses, $output); @@ -57,21 +57,21 @@ do_test(array('ignore_errors' => 1)); resource(%d) of type (stream) array(2) { [0]=> - string(15) "HTTP/1.0 200 Ok" + string(15) "HTTP/1.1 200 Ok" [1]=> string(10) "X-Foo: bar" } string(1) "1" -string(%d) "GET /foo/bar HTTP/1.0 +string(%d) "GET /foo/bar HTTP/1.1 Host: 127.0.0.1:12342 Connection: close " -Warning: fopen(http://127.0.0.1:12342/foo/bar): Failed to open stream: HTTP request failed! HTTP/1.0 404 Not found +Warning: fopen(http://127.0.0.1:12342/foo/bar): Failed to open stream: HTTP request failed! HTTP/1.1 404 Not found in %s on line %d bool(false) -string(%d) "GET /foo/bar HTTP/1.0 +string(%d) "GET /foo/bar HTTP/1.1 Host: 127.0.0.1:12342 Connection: close @@ -80,12 +80,12 @@ Connection: close resource(%d) of type (stream) array(2) { [0]=> - string(15) "HTTP/1.0 200 Ok" + string(15) "HTTP/1.1 200 Ok" [1]=> string(10) "X-Foo: bar" } string(1) "1" -string(%d) "GET /foo/bar HTTP/1.0 +string(%d) "GET /foo/bar HTTP/1.1 Host: 127.0.0.1:12342 Connection: close @@ -93,12 +93,12 @@ Connection: close resource(%d) of type (stream) array(2) { [0]=> - string(22) "HTTP/1.0 404 Not found" + string(22) "HTTP/1.1 404 Not found" [1]=> string(10) "X-bar: baz" } string(1) "2" -string(%d) "GET /foo/bar HTTP/1.0 +string(%d) "GET /foo/bar HTTP/1.1 Host: 127.0.0.1:12342 Connection: close @@ -107,12 +107,12 @@ Connection: close resource(%d) of type (stream) array(2) { [0]=> - string(15) "HTTP/1.0 200 Ok" + string(15) "HTTP/1.1 200 Ok" [1]=> string(10) "X-Foo: bar" } string(1) "1" -string(%d) "GET /foo/bar HTTP/1.0 +string(%d) "GET /foo/bar HTTP/1.1 Host: 127.0.0.1:12342 Connection: close @@ -120,12 +120,12 @@ Connection: close resource(%d) of type (stream) array(2) { [0]=> - string(22) "HTTP/1.0 404 Not found" + string(22) "HTTP/1.1 404 Not found" [1]=> string(10) "X-bar: baz" } string(1) "2" -string(%d) "GET /foo/bar HTTP/1.0 +string(%d) "GET /foo/bar HTTP/1.1 Host: 127.0.0.1:12342 Connection: close diff --git a/sapi/cli/tests/bug69655.phpt b/sapi/cli/tests/bug69655.phpt index dbb9a6af40..b5612357f9 100644 --- a/sapi/cli/tests/bug69655.phpt +++ b/sapi/cli/tests/bug69655.phpt @@ -17,11 +17,11 @@ foreach (['MKCO', 'MKCOLL', 'M'] as $method) { } ?> --EXPECTF-- -Warning: file_get_contents(http://localhost:8964): Failed to open stream: HTTP request failed! HTTP/1.0 501 Not Implemented +Warning: file_get_contents(http://localhost:8964): Failed to open stream: HTTP request failed! HTTP/1.1 501 Not Implemented in %s on line %d -Warning: file_get_contents(http://localhost:8964): Failed to open stream: HTTP request failed! HTTP/1.0 501 Not Implemented +Warning: file_get_contents(http://localhost:8964): Failed to open stream: HTTP request failed! HTTP/1.1 501 Not Implemented in %s on line %d -Warning: file_get_contents(http://localhost:8964): Failed to open stream: HTTP request failed! HTTP/1.0 501 Not Implemented +Warning: file_get_contents(http://localhost:8964): Failed to open stream: HTTP request failed! HTTP/1.1 501 Not Implemented in %s on line %d diff --git a/sapi/cli/tests/bug70264.phpt b/sapi/cli/tests/bug70264.phpt index 6d4ee15273..e1b0ee8fe8 100644 --- a/sapi/cli/tests/bug70264.phpt +++ b/sapi/cli/tests/bug70264.phpt @@ -14,8 +14,8 @@ echo file_get_contents("http://" . PHP_CLI_SERVER_ADDRESS . "/..\\CREDITS"); echo file_get_contents("http://" . PHP_CLI_SERVER_ADDRESS . "/..%5CCREDITS"); ?> --EXPECTF-- -Warning: file_get_contents(http://%s/..\CREDITS): Failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found +Warning: file_get_contents(http://%s/..\CREDITS): Failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in %sbug70264.php on line %d -Warning: file_get_contents(http://%s/..%5CCREDITS): Failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found +Warning: file_get_contents(http://%s/..%5CCREDITS): Failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in %sbug70264.php on line %d |