]> granicus.if.org Git - php/commitdiff
Make http stream wrapper advertise HTTP/1.1 by default
authorRowan Tommins <git@rwec.co.uk>
Thu, 11 Jun 2020 18:05:00 +0000 (19:05 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 3 Aug 2020 14:30:09 +0000 (16:30 +0200)
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.

12 files changed:
UPGRADING
ext/standard/http_fopen_wrapper.c
ext/standard/tests/http/bug38802.phpt
ext/standard/tests/http/bug48929.phpt
ext/standard/tests/http/bug53198.phpt
ext/standard/tests/http/bug61548.phpt
ext/standard/tests/http/bug67430.phpt
ext/standard/tests/http/bug79265.phpt
ext/standard/tests/http/bug79265_2.phpt
ext/standard/tests/http/ignore_errors.phpt
sapi/cli/tests/bug69655.phpt
sapi/cli/tests/bug70264.phpt

index 78eac70d71ab669ecfca8a5e3542250b1af58de5..52443866555c856a61c904b8edee839844e15452 100644 (file)
--- a/UPGRADING
+++ b/UPGRADING
@@ -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
index ae9b915101885902be0bd6d13aa0de8561a550fa..ac57c55efb4c82cdab7ad8aa18821bc0ffe932a8 100644 (file)
@@ -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) {
index 77fa16b5e4e51519ea601c7afc58e78e3d0181cb..dc00a834c180721b75f1944ca11d66561de857d1 100644 (file)
@@ -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
 
index 9a769d8674b4f7390ee87aa21cf9c0d53877a6a2..fad8775b6a8e4cd9d71af2910a9f589919bc8093 100644 (file)
@@ -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
index add07c3f472ff4ad58e77f1b1c36d085e125b3d0..da2a4cf15f71768963f2d8d98ea28a7f249580c3 100644 (file)
@@ -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
index 04ea55341b72d1b31d9151570317e65f199d97b1..24e709bf36204effa48cdf764ea1e8cda5bb694a 100644 (file)
@@ -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
index a563951cd8c449425f77491edc6e6063c34aaff5..cf8db65cf163f6e33653e732e1e92969aec727fd 100644 (file)
@@ -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
 
index 4848991bd0fbedaa4e036ed7ad6631bc9d58a871..25efdd089a11a97e69d26bf2135a675c22d095de 100644 (file)
@@ -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
index d2f5bc1e384cf0b9cc600b893a6966c724fd66a0..0cdde1050152fe0664cac84e54e9ff6ecb0cb351 100644 (file)
@@ -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
index 38a1cf698537d97b0d6b461d5d9894ad15557968..436fceeef9035e63c7cb30b5900314ea3a49d3d2 100644 (file)
@@ -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
 
index dbb9a6af400024510b058984b096cda273cdbbe6..b5612357f9016fcf0e3115bd464f04ee14abe7fb 100644 (file)
@@ -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
index 6d4ee15273a942cc5e273b538876301a6f4cfcdc..e1b0ee8fe8b195d64394a2a84d8bafcdb2828953 100644 (file)
@@ -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