summaryrefslogtreecommitdiff
path: root/ext/standard/tests/http
diff options
context:
space:
mode:
authorNikita Popov <nikic@php.net>2017-01-07 23:55:20 +0100
committerNikita Popov <nikic@php.net>2017-01-07 23:55:48 +0100
commitd48ff0f3f53598bbc5193dbc32a78f3624192025 (patch)
tree65f567b2782b108e64503191b1052bc33d9dfa20 /ext/standard/tests/http
parentbb2ab755555af61798c8584a166448119dcd9314 (diff)
parent5146d9f8ac170d8ba7109370d732d56dc0777578 (diff)
downloadphp-git-d48ff0f3f53598bbc5193dbc32a78f3624192025.tar.gz
Merge branch 'PHP-7.0' into PHP-7.1
Diffstat (limited to 'ext/standard/tests/http')
-rw-r--r--ext/standard/tests/http/bug47021.phpt93
-rw-r--r--ext/standard/tests/http/http_response_header_04.phpt37
-rw-r--r--ext/standard/tests/http/http_response_header_05.phpt37
3 files changed, 167 insertions, 0 deletions
diff --git a/ext/standard/tests/http/bug47021.phpt b/ext/standard/tests/http/bug47021.phpt
new file mode 100644
index 0000000000..6cdfda6a6b
--- /dev/null
+++ b/ext/standard/tests/http/bug47021.phpt
@@ -0,0 +1,93 @@
+--TEST--
+Bug #47021 (SoapClient stumbles over WSDL delivered with "Transfer-Encoding: chunked")
+--INI--
+allow_url_fopen=1
+--SKIPIF--
+<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:12342'); ?>
+--FILE--
+<?php
+require 'server.inc';
+
+function stream_notification_callback($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max) {
+
+ switch($notification_code) {
+ case STREAM_NOTIFY_MIME_TYPE_IS:
+ echo "Type='$message'\n";
+ break;
+ case STREAM_NOTIFY_FILE_SIZE_IS:
+ echo "Size=$bytes_max\n";
+ break;
+ }
+}
+
+function do_test($num_spaces, $leave_trailing_space=false) {
+ // SOAPClient exhibits the bug because it forces HTTP/1.1,
+ // whereas file_get_contents() uses HTTP/1.0 by default.
+ $options = [
+ 'http' => [
+ 'protocol_version' => '1.1',
+ 'header' => 'Connection: Close'
+ ],
+ ];
+
+ $ctx = stream_context_create($options);
+ stream_context_set_params($ctx, array("notification" => "stream_notification_callback"));
+
+ $spaces = str_repeat(' ', $num_spaces);
+ $trailing = ($leave_trailing_space ? ' ' : '');
+ $responses = [
+ "data://text/plain,HTTP/1.1 200 OK\r\n"
+ . "Content-Type:{$spaces}text/plain{$trailing}\r\n"
+ . "Transfer-Encoding:{$spaces}Chunked{$trailing}\r\n\r\n"
+ . "5\nHello\n0\n",
+ "data://text/plain,HTTP/1.1 200 OK\r\n"
+ . "Content-Type\r\n" // Deliberately invalid header
+ . "Content-Length:{$spaces}5{$trailing}\r\n\r\n"
+ . "World"
+ ];
+ $pid = http_server('tcp://127.0.0.1:12342', $responses);
+
+ echo file_get_contents('http://127.0.0.1:12342/', false, $ctx);
+ echo "\n";
+ echo file_get_contents('http://127.0.0.1:12342/', false, $ctx);
+ echo "\n";
+
+ http_server_kill($pid);
+}
+
+// Chunked decoding should be recognised by the HTTP stream wrapper regardless of whitespace
+// Transfer-Encoding:Chunked
+do_test(0);
+echo "\n";
+// Transfer-Encoding: Chunked
+do_test(1);
+echo "\n";
+// Transfer-Encoding: Chunked
+do_test(2);
+echo "\n";
+// Trailing space at end of header
+do_test(1, true);
+echo "\n";
+
+?>
+--EXPECT--
+Type='text/plain'
+Hello
+Size=5
+World
+
+Type='text/plain'
+Hello
+Size=5
+World
+
+Type='text/plain'
+Hello
+Size=5
+World
+
+Type='text/plain'
+Hello
+Size=5
+World
+
diff --git a/ext/standard/tests/http/http_response_header_04.phpt b/ext/standard/tests/http/http_response_header_04.phpt
new file mode 100644
index 0000000000..e8f22e00b1
--- /dev/null
+++ b/ext/standard/tests/http/http_response_header_04.phpt
@@ -0,0 +1,37 @@
+--TEST--
+$http_reponse_header (header with trailing whitespace)
+--SKIPIF--
+<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:22349'); ?>
+--INI--
+allow_url_fopen=1
+allow_url_include=1
+--FILE--
+<?php
+require 'server.inc';
+
+$responses = array(
+ "data://text/plain,HTTP/1.0 200 Ok\r\nSome: Header \r\n\r\nBody",
+);
+
+$pid = http_server("tcp://127.0.0.1:22349", $responses, $output);
+
+function test() {
+ $f = file_get_contents('http://127.0.0.1:22349/');
+ var_dump($f);
+ var_dump($http_response_header);
+}
+test();
+
+http_server_kill($pid);
+?>
+==DONE==
+--EXPECT--
+string(4) "Body"
+array(2) {
+ [0]=>
+ string(15) "HTTP/1.0 200 Ok"
+ [1]=>
+ string(14) "Some: Header"
+}
+==DONE==
+
diff --git a/ext/standard/tests/http/http_response_header_05.phpt b/ext/standard/tests/http/http_response_header_05.phpt
new file mode 100644
index 0000000000..27ba77adcc
--- /dev/null
+++ b/ext/standard/tests/http/http_response_header_05.phpt
@@ -0,0 +1,37 @@
+--TEST--
+$http_reponse_header (whitespace-only "header")
+--SKIPIF--
+<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:22350'); ?>
+--INI--
+allow_url_fopen=1
+allow_url_include=1
+--FILE--
+<?php
+require 'server.inc';
+
+$responses = array(
+ "data://text/plain,HTTP/1.0 200 Ok\r\n \r\n\r\nBody",
+);
+
+$pid = http_server("tcp://127.0.0.1:22350", $responses, $output);
+
+function test() {
+ $f = file_get_contents('http://127.0.0.1:22350/');
+ var_dump($f);
+ var_dump($http_response_header);
+}
+test();
+
+http_server_kill($pid);
+?>
+==DONE==
+--EXPECT--
+string(4) "Body"
+array(2) {
+ [0]=>
+ string(15) "HTTP/1.0 200 Ok"
+ [1]=>
+ string(0) ""
+}
+==DONE==
+