mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Allow http tests to run in parallel by using ephemeral ports
This commit is contained in:
parent
cafeec34f9
commit
95f2583743
26 changed files with 193 additions and 210 deletions
|
@ -4,12 +4,9 @@ Bug #47021 SoapClient (SoapClient stumbles over WSDL delivered with "Transfer-En
|
|||
soap.wsdl_cache_enabled=0
|
||||
--SKIPIF--
|
||||
<?php
|
||||
|
||||
require 'skipif.inc';
|
||||
|
||||
require __DIR__.'/../../standard/tests/http/server.inc'; http_server_skipif('tcp://127.0.0.1:12342');
|
||||
|
||||
?>
|
||||
require __DIR__.'/../../standard/tests/http/server.inc';
|
||||
http_server_skipif();
|
||||
--FILE--
|
||||
<?php
|
||||
require __DIR__.'/../../standard/tests/http/server.inc';
|
||||
|
@ -49,11 +46,11 @@ $responses = [
|
|||
];
|
||||
|
||||
|
||||
$pid = http_server('tcp://127.0.0.1:12342', $responses);
|
||||
['pid' => $pid, 'uri' => $uri] = http_server($responses);
|
||||
|
||||
$options = [
|
||||
'trace' => true,
|
||||
'location' => 'http://127.0.0.1:12342/',
|
||||
'location' => $uri,
|
||||
];
|
||||
|
||||
class BugSoapClient extends SoapClient
|
||||
|
@ -68,13 +65,12 @@ class BugSoapClient extends SoapClient
|
|||
}
|
||||
}
|
||||
|
||||
$client = new BugSoapClient('http://127.0.0.1:12342/', $options);
|
||||
$client = new BugSoapClient($uri, $options);
|
||||
|
||||
var_dump(count($client->getItems()));
|
||||
|
||||
http_server_kill($pid);
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
int(1291)
|
||||
int(10)
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
server
|
|
@ -3,25 +3,27 @@ Bug #38802 (ignore_errors and max_redirects)
|
|||
--INI--
|
||||
allow_url_fopen=1
|
||||
--SKIPIF--
|
||||
<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:12342'); ?>
|
||||
<?php require 'server.inc'; http_server_skipif();
|
||||
--FILE--
|
||||
<?php
|
||||
require 'server.inc';
|
||||
|
||||
function genResponses($server) {
|
||||
$uri = 'http://' . stream_socket_get_name($server, false);
|
||||
yield "data://text/plain,HTTP/1.1 302 Moved Temporarily\r\nLocation: $uri/foo/bar2\r\n\r\n1";
|
||||
yield "data://text/plain,HTTP/1.1 301 Moved Permanently\r\nLocation: $uri/foo/bar3\r\n\r\n";
|
||||
yield "data://text/plain,HTTP/1.1 302 Moved Temporarily\r\nLocation: $uri/foo/bar4\r\n\r\n3";
|
||||
yield "data://text/plain,HTTP/1.1 200 OK\r\n\r\ndone.";
|
||||
}
|
||||
|
||||
function do_test($context_options) {
|
||||
|
||||
$context = stream_context_create(array('http' => $context_options));
|
||||
|
||||
$responses = array(
|
||||
"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.",
|
||||
);
|
||||
$uri = null;
|
||||
['pid' => $pid, 'uri' => $uri ] = http_server('genResponses', $output);
|
||||
|
||||
$pid = http_server("tcp://127.0.0.1:12342", $responses, $output);
|
||||
|
||||
$fd = fopen('http://127.0.0.1:12342/foo/bar', 'rb', false, $context);
|
||||
$fd = fopen("$uri/foo/bar", 'rb', false, $context);
|
||||
var_dump($fd);
|
||||
|
||||
if ($fd) {
|
||||
|
@ -73,64 +75,64 @@ array(7) {
|
|||
[0]=>
|
||||
string(30) "HTTP/1.1 302 Moved Temporarily"
|
||||
[1]=>
|
||||
string(41) "Location: http://127.0.0.1:12342/foo/bar2"
|
||||
string(%d) "Location: http://%s:%d/foo/bar2"
|
||||
[2]=>
|
||||
string(30) "HTTP/1.1 301 Moved Permanently"
|
||||
[3]=>
|
||||
string(41) "Location: http://127.0.0.1:12342/foo/bar3"
|
||||
string(%d) "Location: http://%s:%d/foo/bar3"
|
||||
[4]=>
|
||||
string(30) "HTTP/1.1 302 Moved Temporarily"
|
||||
[5]=>
|
||||
string(41) "Location: http://127.0.0.1:12342/foo/bar4"
|
||||
string(%d) "Location: http://%s:%d/foo/bar4"
|
||||
[6]=>
|
||||
string(15) "HTTP/1.1 200 OK"
|
||||
}
|
||||
string(5) "done."
|
||||
string(%d) "GET /foo/bar HTTP/1.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
|
||||
GET /foo/bar2 HTTP/1.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
|
||||
GET /foo/bar3 HTTP/1.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
|
||||
GET /foo/bar4 HTTP/1.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
|
||||
"
|
||||
-- Test: fail after 2 redirections --
|
||||
|
||||
Warning: fopen(http://127.0.0.1:12342/foo/bar): Failed to open stream: Redirection limit reached, aborting in %s
|
||||
Warning: fopen(http://%s:%d/foo/bar): Failed to open stream: Redirection limit reached, aborting in %s
|
||||
bool(false)
|
||||
string(%d) "GET /foo/bar HTTP/1.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
|
||||
GET /foo/bar2 HTTP/1.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
|
||||
"
|
||||
-- Test: fail at first redirection --
|
||||
|
||||
Warning: fopen(http://127.0.0.1:12342/foo/bar): Failed to open stream: Redirection limit reached, aborting in %s
|
||||
Warning: fopen(http://%s:%d/foo/bar): Failed to open stream: Redirection limit reached, aborting in %s
|
||||
bool(false)
|
||||
string(%d) "GET /foo/bar HTTP/1.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
|
||||
"
|
||||
-- Test: fail at first redirection (2) --
|
||||
|
||||
Warning: fopen(http://127.0.0.1:12342/foo/bar): Failed to open stream: Redirection limit reached, aborting in %s
|
||||
Warning: fopen(http://%s:%d/foo/bar): Failed to open stream: Redirection limit reached, aborting in %s
|
||||
bool(false)
|
||||
string(%d) "GET /foo/bar HTTP/1.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
|
||||
"
|
||||
|
@ -140,11 +142,11 @@ array(2) {
|
|||
[0]=>
|
||||
string(30) "HTTP/1.1 302 Moved Temporarily"
|
||||
[1]=>
|
||||
string(41) "Location: http://127.0.0.1:12342/foo/bar2"
|
||||
string(%d) "Location: http://%s:%d/foo/bar2"
|
||||
}
|
||||
string(1) "1"
|
||||
string(%d) "GET /foo/bar HTTP/1.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
|
||||
"
|
||||
|
@ -154,11 +156,11 @@ array(2) {
|
|||
[0]=>
|
||||
string(30) "HTTP/1.1 302 Moved Temporarily"
|
||||
[1]=>
|
||||
string(41) "Location: http://127.0.0.1:12342/foo/bar2"
|
||||
string(%d) "Location: http://%s:%d/foo/bar2"
|
||||
}
|
||||
string(1) "1"
|
||||
string(%d) "GET /foo/bar HTTP/1.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
|
||||
"
|
||||
|
@ -168,19 +170,19 @@ array(4) {
|
|||
[0]=>
|
||||
string(30) "HTTP/1.1 302 Moved Temporarily"
|
||||
[1]=>
|
||||
string(41) "Location: http://127.0.0.1:12342/foo/bar2"
|
||||
string(%d) "Location: http://%s:%d/foo/bar2"
|
||||
[2]=>
|
||||
string(30) "HTTP/1.1 301 Moved Permanently"
|
||||
[3]=>
|
||||
string(41) "Location: http://127.0.0.1:12342/foo/bar3"
|
||||
string(%d) "Location: http://%s:%d/foo/bar3"
|
||||
}
|
||||
string(0) ""
|
||||
string(%d) "GET /foo/bar HTTP/1.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
|
||||
GET /foo/bar2 HTTP/1.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
|
||||
"
|
||||
|
|
|
@ -3,7 +3,7 @@ Bug #43510 (stream_get_meta_data() does not return same mode as used in fopen)
|
|||
--INI--
|
||||
allow_url_fopen=1
|
||||
--SKIPIF--
|
||||
<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:12342'); ?>
|
||||
<?php require 'server.inc'; http_server_skipif(); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require 'server.inc';
|
||||
|
@ -13,10 +13,10 @@ $responses = array(
|
|||
"data://text/plain,HTTP/1.0 200 OK\r\n\r\n",
|
||||
);
|
||||
|
||||
$pid = http_server("tcp://127.0.0.1:12342", $responses, $output);
|
||||
['pid' => $pid, 'uri' => $uri ] = http_server($responses, $output);
|
||||
|
||||
foreach(array('r', 'rb') as $mode) {
|
||||
$fd = fopen('http://127.0.0.1:12342/', $mode, false);
|
||||
$fd = fopen($uri, $mode, false);
|
||||
$meta = stream_get_meta_data($fd);
|
||||
var_dump($meta['mode']);
|
||||
fclose($fd);
|
||||
|
|
|
@ -3,7 +3,7 @@ Bug #47021 (SoapClient stumbles over WSDL delivered with "Transfer-Encoding: chu
|
|||
--INI--
|
||||
allow_url_fopen=1
|
||||
--SKIPIF--
|
||||
<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:12342'); ?>
|
||||
<?php require 'server.inc'; http_server_skipif(); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require 'server.inc';
|
||||
|
@ -45,11 +45,11 @@ function do_test($num_spaces, $leave_trailing_space=false) {
|
|||
. "Content-Length:{$spaces}5{$trailing}\r\n\r\n"
|
||||
. "World"
|
||||
];
|
||||
$pid = http_server('tcp://127.0.0.1:12342', $responses);
|
||||
['pid' => $pid, 'uri' => $uri] = http_server($responses);
|
||||
|
||||
echo file_get_contents('http://127.0.0.1:12342/', false, $ctx);
|
||||
echo file_get_contents($uri, false, $ctx);
|
||||
echo "\n";
|
||||
echo file_get_contents('http://127.0.0.1:12342/', false, $ctx);
|
||||
echo file_get_contents($uri, false, $ctx);
|
||||
echo "\n";
|
||||
|
||||
http_server_kill($pid);
|
||||
|
|
|
@ -3,7 +3,7 @@ Bug #48929 (duplicate \r\n sent after last header line)
|
|||
--INI--
|
||||
allow_url_fopen=1
|
||||
--SKIPIF--
|
||||
<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:12342'); ?>
|
||||
<?php require 'server.inc'; http_server_skipif(); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require 'server.inc';
|
||||
|
@ -16,11 +16,11 @@ function do_test($context_options) {
|
|||
"data://text/plain,HTTP/1.1 200 OK\r\n\r\n",
|
||||
);
|
||||
|
||||
$pid = http_server("tcp://127.0.0.1:12342", $responses, $output);
|
||||
['pid' => $pid, 'uri' => $uri] = http_server($responses, $output);
|
||||
|
||||
foreach($responses as $r) {
|
||||
|
||||
$fd = fopen('http://127.0.0.1:12342/', 'rb', false, $context);
|
||||
$fd = fopen($uri, 'rb', false, $context);
|
||||
|
||||
fseek($output, 0, SEEK_SET);
|
||||
var_dump(stream_get_contents($output));
|
||||
|
@ -42,7 +42,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.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
Content-Length: 4
|
||||
X-Foo: bar
|
||||
|
@ -51,7 +51,7 @@ Content-Type: text/plain
|
|||
ohai"
|
||||
-- Test: requests with 'header' as string --
|
||||
string(%d) "POST / HTTP/1.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
Content-Length: 4
|
||||
X-Foo: bar
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
--TEST--
|
||||
Bug #53198 (From: header cannot be changed with ini_set)
|
||||
--SKIPIF--
|
||||
<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:12342'); ?>
|
||||
<?php require 'server.inc'; http_server_skipif(); ?>
|
||||
--INI--
|
||||
allow_url_fopen=1
|
||||
from=teste@teste.pt
|
||||
|
@ -15,11 +15,11 @@ function do_test() {
|
|||
"data://text/plain,HTTP/1.1 200 OK\r\n\r\n",
|
||||
);
|
||||
|
||||
$pid = http_server("tcp://127.0.0.1:12342", $responses, $output);
|
||||
['pid' => $pid, 'uri' => $uri] = http_server($responses, $output);
|
||||
|
||||
foreach($responses as $r) {
|
||||
|
||||
$fd = fopen('http://127.0.0.1:12342/', 'rb', false);
|
||||
$fd = fopen($uri, 'rb', false);
|
||||
|
||||
fseek($output, 0, SEEK_SET);
|
||||
var_dump(stream_get_contents($output));
|
||||
|
@ -45,14 +45,14 @@ do_test();
|
|||
-- Test: leave default --
|
||||
string(%d) "GET / HTTP/1.1
|
||||
From: teste@teste.pt
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
|
||||
"
|
||||
-- Test: after ini_set --
|
||||
string(%d) "GET / HTTP/1.1
|
||||
From: junk@junk.com
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
|
||||
"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
--TEST--
|
||||
Bug #60570 (Stream context leaks when http request fails)
|
||||
--SKIPIF--
|
||||
<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:12342'); ?>
|
||||
<?php require 'server.inc'; http_server_skipif(); ?>
|
||||
--INI--
|
||||
allow_url_fopen=1
|
||||
--FILE--
|
||||
|
@ -16,14 +16,14 @@ function do_test() {
|
|||
"data://text/plain,HTTP/1.0 404 Not Found\r\n\r\n"
|
||||
);
|
||||
|
||||
$pid = http_server("tcp://127.0.0.1:12342", $responses, $output);
|
||||
['pid' => $pid, 'uri' => $uri] = http_server($responses, $output);
|
||||
|
||||
$a = $b = count(get_resources());
|
||||
|
||||
$i = 3;
|
||||
while ($i--) {
|
||||
$context = stream_context_create(array('http'=>array('timeout'=>1)));
|
||||
file_get_contents('http://127.0.0.1:12342/', 0, $context);
|
||||
file_get_contents($uri, 0, $context);
|
||||
unset($context);
|
||||
|
||||
$b = $a;
|
||||
|
@ -39,13 +39,13 @@ function do_test() {
|
|||
do_test();
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: file_get_contents(http://127.0.0.1:12342/): Failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found
|
||||
Warning: file_get_contents(http://%s:%d): Failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found
|
||||
in %s on line %d
|
||||
|
||||
Warning: file_get_contents(http://127.0.0.1:12342/): Failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found
|
||||
Warning: file_get_contents(http://%s:%d): Failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found
|
||||
in %s on line %d
|
||||
|
||||
Warning: file_get_contents(http://127.0.0.1:12342/): Failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found
|
||||
Warning: file_get_contents(http://%s:%d): Failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found
|
||||
in %s on line %d
|
||||
leak? penultimate iteration: %d, last one: %d
|
||||
bool(true)
|
||||
|
|
|
@ -3,7 +3,7 @@ Bug #61548 (content-type must appear at the end of headers)
|
|||
--INI--
|
||||
allow_url_fopen=1
|
||||
--SKIPIF--
|
||||
<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:12342'); ?>
|
||||
<?php require 'server.inc'; http_server_skipif(); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require 'server.inc';
|
||||
|
@ -23,9 +23,9 @@ function do_test($header) {
|
|||
"data://text/plain,HTTP/1.1 201\r\nLocation: /foo\r\n\r\n",
|
||||
"data://text/plain,HTTP/1.1 200\r\nConnection: close\r\n\r\n",
|
||||
];
|
||||
$pid = http_server('tcp://127.0.0.1:12342', $responses, $output);
|
||||
['pid' => $pid, 'uri' => $uri] = http_server($responses, $output);
|
||||
|
||||
$fd = fopen('http://127.0.0.1:12342/', 'rb', false, $ctx);
|
||||
$fd = fopen($uri, 'rb', false, $ctx);
|
||||
fseek($output, 0, SEEK_SET);
|
||||
echo stream_get_contents($output);
|
||||
|
||||
|
@ -41,37 +41,37 @@ do_test("First:1\nContent-type:text/plain\nSecond:2\nThird:");
|
|||
|
||||
?>
|
||||
Done
|
||||
--EXPECT--
|
||||
--EXPECTF--
|
||||
POST / HTTP/1.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
First:1
|
||||
Second:2
|
||||
Content-type: text/plain
|
||||
|
||||
GET /foo HTTP/1.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
First:1
|
||||
Second:2
|
||||
|
||||
|
||||
POST / HTTP/1.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
First:1
|
||||
Second:2
|
||||
Content-type: text/plain
|
||||
|
||||
GET /foo HTTP/1.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
First:1
|
||||
Second:2
|
||||
|
||||
|
||||
POST / HTTP/1.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
First:1
|
||||
Second:2
|
||||
|
@ -79,40 +79,40 @@ Content-type: text/plain
|
|||
Third:
|
||||
|
||||
GET /foo HTTP/1.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
First:1
|
||||
Second:2
|
||||
Third:
|
||||
|
||||
POST / HTTP/1.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
First:1
|
||||
Content-type:text/plain
|
||||
Second:2
|
||||
|
||||
GET /foo HTTP/1.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
First:1
|
||||
Second:2
|
||||
|
||||
POST / HTTP/1.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
First:1
|
||||
Content-type:text/plain
|
||||
Second:2
|
||||
|
||||
GET /foo HTTP/1.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
First:1
|
||||
Second:2
|
||||
|
||||
POST / HTTP/1.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
First:1
|
||||
Content-type:text/plain
|
||||
|
@ -120,7 +120,7 @@ Second:2
|
|||
Third:
|
||||
|
||||
GET /foo HTTP/1.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
First:1
|
||||
Second:2
|
||||
|
|
|
@ -3,7 +3,7 @@ Bug #65634 (HTTP wrapper is very slow with protocol_version 1.1)
|
|||
--INI--
|
||||
allow_url_fopen=1
|
||||
--SKIPIF--
|
||||
<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:12342'); ?>
|
||||
<?php require 'server.inc'; http_server_skipif(); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require 'server.inc';
|
||||
|
@ -22,9 +22,9 @@ function do_test($version, $connection) {
|
|||
$ctx = stream_context_create($options);
|
||||
|
||||
$responses = ["data://text/plain,HTTP/$version 204 No Content\r\n\r\n"];
|
||||
$pid = http_server('tcp://127.0.0.1:12342', $responses, $output);
|
||||
['pid' => $pid, 'uri' => $uri] = http_server($responses, $output);
|
||||
|
||||
$fd = fopen('http://127.0.0.1:12342/', 'rb', false, $ctx);
|
||||
$fd = fopen($uri, 'rb', false, $ctx);
|
||||
fseek($output, 0, SEEK_SET);
|
||||
echo stream_get_contents($output);
|
||||
|
||||
|
@ -48,34 +48,34 @@ do_test('1.1', 'close');
|
|||
|
||||
echo "HTTP/1.1, connection: keep-alive:\n";
|
||||
do_test('1.1', 'keep-alive');
|
||||
?>
|
||||
--EXPECT--
|
||||
|
||||
--EXPECTF--
|
||||
HTTP/1.0, default behaviour:
|
||||
GET / HTTP/1.0
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
|
||||
HTTP/1.0, connection: close:
|
||||
GET / HTTP/1.0
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
|
||||
HTTP/1.0, connection: keep-alive:
|
||||
GET / HTTP/1.0
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: keep-alive
|
||||
|
||||
HTTP/1.1, default behaviour:
|
||||
GET / HTTP/1.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
|
||||
HTTP/1.1, connection: close:
|
||||
GET / HTTP/1.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
|
||||
HTTP/1.1, connection: keep-alive:
|
||||
GET / HTTP/1.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: keep-alive
|
||||
|
|
|
@ -3,7 +3,7 @@ Bug #67430 (http:// wrapper doesn't follow 308 redirects)
|
|||
--INI--
|
||||
allow_url_fopen=1
|
||||
--SKIPIF--
|
||||
<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:12342'); ?>
|
||||
<?php require 'server.inc'; http_server_skipif(); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require 'server.inc';
|
||||
|
@ -22,9 +22,9 @@ function do_test($follow) {
|
|||
"data://text/plain,HTTP/1.1 308\r\nLocation: /foo\r\n\r\n",
|
||||
"data://text/plain,HTTP/1.1 200\r\nConnection: close\r\n\r\n",
|
||||
];
|
||||
$pid = http_server('tcp://127.0.0.1:12342', $responses, $output);
|
||||
['pid' => $pid, 'uri' => $uri] = http_server($responses, $output);
|
||||
|
||||
$fd = fopen('http://127.0.0.1:12342/', 'rb', false, $ctx);
|
||||
$fd = fopen($uri, 'rb', false, $ctx);
|
||||
fseek($output, 0, SEEK_SET);
|
||||
echo stream_get_contents($output);
|
||||
|
||||
|
@ -36,17 +36,17 @@ do_test(false);
|
|||
|
||||
?>
|
||||
Done
|
||||
--EXPECT--
|
||||
--EXPECTF--
|
||||
POST / HTTP/1.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
|
||||
GET /foo HTTP/1.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
|
||||
POST / HTTP/1.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
|
||||
Done
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
--TEST--
|
||||
Bug #69337 (Stream context leaks when http request fails)
|
||||
--SKIPIF--
|
||||
<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:22345'); ?>
|
||||
<?php require 'server.inc'; http_server_skipif(); ?>
|
||||
--INI--
|
||||
allow_url_fopen=1
|
||||
--FILE--
|
||||
|
@ -21,17 +21,17 @@ $ctx = stream_context_create();
|
|||
stream_context_set_params($ctx, array("notification" => "stream_notification_callback"));
|
||||
|
||||
$responses = array(
|
||||
"data://text/plain,HTTP/1.0 302 Found\r\nLocation: http://127.0.0.1:22345/try-again\r\n\r\n",
|
||||
"data://text/plain,HTTP/1.0 302 Found\r\nLocation: /try-again\r\n\r\n",
|
||||
"data://text/plain,HTTP/1.0 404 Not Found\r\n\r\n",
|
||||
);
|
||||
|
||||
$pid = http_server("tcp://127.0.0.1:22345", $responses, $output);
|
||||
['pid' => $pid, 'uri' => $uri] = http_server($responses, $output);
|
||||
|
||||
$f = file_get_contents('http://127.0.0.1:22345/', 0, $ctx);
|
||||
$f = file_get_contents($uri, 0, $ctx);
|
||||
|
||||
http_server_kill($pid);
|
||||
var_dump($f);
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: file_get_contents(http://127.0.0.1:22345/): Failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found%ain %s on line %d
|
||||
Warning: file_get_contents(http://%s:%d): Failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found%ain %s on line %d
|
||||
bool(false)
|
||||
|
|
|
@ -3,7 +3,7 @@ Bug #73297 (Ignore 100 Continue returned by HTTP/1.1 servers)
|
|||
--INI--
|
||||
allow_url_fopen=1
|
||||
--SKIPIF--
|
||||
<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:12342'); ?>
|
||||
<?php require 'server.inc'; http_server_skipif(); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require 'server.inc';
|
||||
|
@ -21,13 +21,12 @@ $responses = [
|
|||
"data://text/plain,HTTP/1.1 100 Continue\r\n\r\nHTTP/1.1 200 OK\r\n\r\n"
|
||||
. "Hello"
|
||||
];
|
||||
$pid = http_server('tcp://127.0.0.1:12342', $responses);
|
||||
['pid' => $pid, 'uri' => $uri] = http_server($responses);
|
||||
|
||||
echo file_get_contents('http://127.0.0.1:12342/', false, $ctx);
|
||||
echo file_get_contents($uri, false, $ctx);
|
||||
echo "\n";
|
||||
|
||||
http_server_kill($pid);
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
Hello
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
--TEST--
|
||||
Bug #75535: Inappropriately parsing HTTP response leads to PHP segment fault
|
||||
--SKIPIF--
|
||||
<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:22351'); ?>
|
||||
<?php require 'server.inc'; http_server_skipif(); ?>
|
||||
--INI--
|
||||
allow_url_fopen=1
|
||||
--FILE--
|
||||
|
@ -12,13 +12,13 @@ $responses = array(
|
|||
"data://text/plain,HTTP/1.0 200 Ok\r\nContent-Length\r\n",
|
||||
);
|
||||
|
||||
$pid = http_server("tcp://127.0.0.1:22351", $responses, $output);
|
||||
['pid' => $pid, 'uri' => $uri] = http_server($responses, $output);
|
||||
|
||||
var_dump(file_get_contents('http://127.0.0.1:22351/'));
|
||||
var_dump(file_get_contents($uri));
|
||||
var_dump($http_response_header);
|
||||
|
||||
http_server_kill($pid);
|
||||
?>
|
||||
|
||||
--EXPECT--
|
||||
string(0) ""
|
||||
array(2) {
|
||||
|
|
|
@ -3,7 +3,7 @@ Bug #75981 (stack-buffer-overflow while parsing HTTP response)
|
|||
--INI--
|
||||
allow_url_fopen=1
|
||||
--SKIPIF--
|
||||
<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:12342'); ?>
|
||||
<?php require 'server.inc'; http_server_skipif(); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require 'server.inc';
|
||||
|
@ -20,9 +20,9 @@ $ctx = stream_context_create($options);
|
|||
$responses = [
|
||||
"data://text/plain,000000000100\xA\xA"
|
||||
];
|
||||
$pid = http_server('tcp://127.0.0.1:12342', $responses);
|
||||
['pid' => $pid, 'uri' => $uri] = http_server($responses);
|
||||
|
||||
echo @file_get_contents('http://127.0.0.1:12342/', false, $ctx);
|
||||
echo @file_get_contents($uri, false, $ctx);
|
||||
|
||||
http_server_kill($pid);
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ Bug #76342 (file_get_contents waits twice specified timeout)
|
|||
--INI--
|
||||
allow_url_fopen=1
|
||||
--SKIPIF--
|
||||
<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:12342'); ?>
|
||||
<?php require 'server.inc'; http_server_skipif(); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require 'server.inc';
|
||||
|
@ -17,10 +17,10 @@ $options = [
|
|||
|
||||
$ctx = stream_context_create($options);
|
||||
|
||||
$pid = http_server_sleep('tcp://127.0.0.1:12342');
|
||||
['pid' => $pid, 'uri' => $uri] = http_server_sleep();
|
||||
|
||||
$start = microtime(true);
|
||||
file_get_contents('http://127.0.0.1:12342/', false, $ctx);
|
||||
file_get_contents($uri, false, $ctx);
|
||||
$diff = microtime(true) - $start;
|
||||
if ($diff >= 2 * $timeout) {
|
||||
echo "FAIL: $diff\n";
|
||||
|
@ -31,5 +31,5 @@ http_server_kill($pid);
|
|||
?>
|
||||
DONE
|
||||
--EXPECTF--
|
||||
Warning: file_get_contents(http://127.0.0.1:12342/): Failed to open stream: HTTP request failed! in %s on line %d
|
||||
Warning: file_get_contents(http://%s:%d): Failed to open stream: HTTP request failed! in %s on line %d
|
||||
DONE
|
||||
|
|
|
@ -3,7 +3,7 @@ Bug #79265 (Improper injection of Host header when using fopen for http requests
|
|||
--INI--
|
||||
allow_url_fopen=1
|
||||
--SKIPIF--
|
||||
<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:12342'); ?>
|
||||
<?php require 'server.inc'; http_server_skipif(); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require 'server.inc';
|
||||
|
@ -12,7 +12,7 @@ $responses = array(
|
|||
"data://text/plain,HTTP/1.1 200 OK\r\n\r\n",
|
||||
);
|
||||
|
||||
$pid = http_server("tcp://127.0.0.1:12342", $responses, $output);
|
||||
['pid' => $pid, 'uri' => $uri] = http_server($responses, $output);
|
||||
|
||||
$opts = array(
|
||||
'http'=>array(
|
||||
|
@ -23,14 +23,13 @@ $opts = array(
|
|||
)
|
||||
);
|
||||
$context = stream_context_create($opts);
|
||||
$fd = fopen('http://127.0.0.1:12342/', 'rb', false, $context);
|
||||
$fd = fopen($uri, 'rb', false, $context);
|
||||
fseek($output, 0, SEEK_SET);
|
||||
echo stream_get_contents($output);
|
||||
fclose($fd);
|
||||
|
||||
http_server_kill($pid);
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
GET / HTTP/1.1
|
||||
Connection: close
|
||||
|
|
|
@ -3,7 +3,7 @@ Bug #79265 variation: "host:" not at start of header
|
|||
--INI--
|
||||
allow_url_fopen=1
|
||||
--SKIPIF--
|
||||
<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:12342'); ?>
|
||||
<?php require 'server.inc'; http_server_skipif(); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require 'server.inc';
|
||||
|
@ -12,7 +12,7 @@ $responses = array(
|
|||
"data://text/plain,HTTP/1.1 200 OK\r\n\r\n",
|
||||
);
|
||||
|
||||
$pid = http_server("tcp://127.0.0.1:12342", $responses, $output);
|
||||
['pid' => $pid, 'uri' => $uri] = http_server($responses, $output);
|
||||
|
||||
$opts = array(
|
||||
'http'=>array(
|
||||
|
@ -22,17 +22,16 @@ $opts = array(
|
|||
)
|
||||
);
|
||||
$context = stream_context_create($opts);
|
||||
$fd = fopen('http://127.0.0.1:12342/', 'rb', false, $context);
|
||||
$fd = fopen($uri, 'rb', false, $context);
|
||||
fseek($output, 0, SEEK_SET);
|
||||
echo stream_get_contents($output);
|
||||
fclose($fd);
|
||||
|
||||
http_server_kill($pid);
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
--EXPECTF--
|
||||
GET / HTTP/1.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
RandomHeader: host:8080
|
||||
Cookie: foo=bar
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
--TEST--
|
||||
$http_reponse_header (no redirect)
|
||||
--SKIPIF--
|
||||
<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:22346'); ?>
|
||||
<?php require 'server.inc'; http_server_skipif(); ?>
|
||||
--INI--
|
||||
allow_url_fopen=1
|
||||
--FILE--
|
||||
|
@ -12,17 +12,14 @@ $responses = array(
|
|||
"data://text/plain,HTTP/1.0 200 Ok\r\nSome: Header\r\nSome: Header\r\n\r\nBody",
|
||||
);
|
||||
|
||||
$pid = http_server("tcp://127.0.0.1:22346", $responses, $output);
|
||||
['pid' => $pid, 'uri' => $uri] = http_server($responses, $output);
|
||||
|
||||
function test() {
|
||||
$f = file_get_contents('http://127.0.0.1:22346/');
|
||||
var_dump($f);
|
||||
var_dump($http_response_header);
|
||||
}
|
||||
test();
|
||||
$f = file_get_contents($uri);
|
||||
var_dump($f);
|
||||
var_dump($http_response_header);
|
||||
|
||||
http_server_kill($pid);
|
||||
?>
|
||||
|
||||
--EXPECT--
|
||||
string(4) "Body"
|
||||
array(3) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
--TEST--
|
||||
$http_reponse_header (redirect)
|
||||
--SKIPIF--
|
||||
<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:22347'); ?>
|
||||
<?php require 'server.inc'; http_server_skipif(); ?>
|
||||
--INI--
|
||||
allow_url_fopen=1
|
||||
--FILE--
|
||||
|
@ -10,21 +10,18 @@ require 'server.inc';
|
|||
|
||||
$responses = array(
|
||||
"data://text/plain,HTTP/1.0 302 Found\r\n"
|
||||
. "Some: Header\r\nLocation: http://127.0.0.1:22347/try-again\r\n\r\n",
|
||||
. "Some: Header\r\nLocation: /try-again\r\n\r\n",
|
||||
"data://test/plain,HTTP/1.0 200 Ok\r\nSome: Header\r\n\r\nBody",
|
||||
);
|
||||
|
||||
$pid = http_server("tcp://127.0.0.1:22347", $responses, $output);
|
||||
['pid' => $pid, 'uri' => $uri] = http_server($responses, $output);
|
||||
|
||||
function test() {
|
||||
$f = file_get_contents('http://127.0.0.1:22347/');
|
||||
var_dump($f);
|
||||
var_dump($http_response_header);
|
||||
}
|
||||
test();
|
||||
$f = file_get_contents($uri);
|
||||
var_dump($f);
|
||||
var_dump($http_response_header);
|
||||
|
||||
http_server_kill($pid);
|
||||
?>
|
||||
|
||||
--EXPECT--
|
||||
string(4) "Body"
|
||||
array(5) {
|
||||
|
@ -33,7 +30,7 @@ array(5) {
|
|||
[1]=>
|
||||
string(12) "Some: Header"
|
||||
[2]=>
|
||||
string(42) "Location: http://127.0.0.1:22347/try-again"
|
||||
string(20) "Location: /try-again"
|
||||
[3]=>
|
||||
string(15) "HTTP/1.0 200 Ok"
|
||||
[4]=>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
--TEST--
|
||||
$http_reponse_header (redirect + not found)
|
||||
--SKIPIF--
|
||||
<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:22348'); ?>
|
||||
<?php require 'server.inc'; http_server_skipif(); ?>
|
||||
--INI--
|
||||
allow_url_fopen=1
|
||||
--FILE--
|
||||
|
@ -10,23 +10,20 @@ require 'server.inc';
|
|||
|
||||
$responses = array(
|
||||
"data://text/plain,HTTP/1.0 302 Found\r\n"
|
||||
. "Some: Header\r\nLocation: http://127.0.0.1:22348/try-again\r\n\r\n",
|
||||
. "Some: Header\r\nLocation: /try-again\r\n\r\n",
|
||||
"data://test/plain,HTTP/1.0 404 Not Found\r\nSome: Header\r\n\r\nBody",
|
||||
);
|
||||
|
||||
$pid = http_server("tcp://127.0.0.1:22348", $responses, $output);
|
||||
['pid' => $pid, 'uri' => $uri] = http_server($responses, $output);
|
||||
|
||||
function test() {
|
||||
$f = file_get_contents('http://127.0.0.1:22348/');
|
||||
var_dump($f);
|
||||
var_dump($http_response_header);
|
||||
}
|
||||
test();
|
||||
$f = file_get_contents($uri);
|
||||
var_dump($f);
|
||||
var_dump($http_response_header);
|
||||
|
||||
http_server_kill($pid);
|
||||
?>
|
||||
|
||||
--EXPECTF--
|
||||
Warning: file_get_contents(http://127.0.0.1:22348/): Failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found%a
|
||||
Warning: file_get_contents(http://%s:%d): Failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found%a
|
||||
bool(false)
|
||||
array(5) {
|
||||
[0]=>
|
||||
|
@ -34,7 +31,7 @@ array(5) {
|
|||
[1]=>
|
||||
string(12) "Some: Header"
|
||||
[2]=>
|
||||
string(42) "Location: http://127.0.0.1:22348/try-again"
|
||||
string(20) "Location: /try-again"
|
||||
[3]=>
|
||||
string(22) "HTTP/1.0 404 Not Found"
|
||||
[4]=>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
--TEST--
|
||||
$http_reponse_header (header with trailing whitespace)
|
||||
--SKIPIF--
|
||||
<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:22349'); ?>
|
||||
<?php require 'server.inc'; http_server_skipif(); ?>
|
||||
--INI--
|
||||
allow_url_fopen=1
|
||||
--FILE--
|
||||
|
@ -12,17 +12,14 @@ $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);
|
||||
['pid' => $pid, 'uri' => $uri] = http_server($responses, $output);
|
||||
|
||||
function test() {
|
||||
$f = file_get_contents('http://127.0.0.1:22349/');
|
||||
var_dump($f);
|
||||
var_dump($http_response_header);
|
||||
}
|
||||
test();
|
||||
$f = file_get_contents($uri);
|
||||
var_dump($f);
|
||||
var_dump($http_response_header);
|
||||
|
||||
http_server_kill($pid);
|
||||
?>
|
||||
|
||||
--EXPECT--
|
||||
string(4) "Body"
|
||||
array(2) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
--TEST--
|
||||
$http_reponse_header (whitespace-only "header")
|
||||
--SKIPIF--
|
||||
<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:22350'); ?>
|
||||
<?php require 'server.inc'; http_server_skipif(); ?>
|
||||
--INI--
|
||||
allow_url_fopen=1
|
||||
--FILE--
|
||||
|
@ -12,17 +12,14 @@ $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);
|
||||
['pid' => $pid, 'uri' => $uri] = http_server($responses, $output);
|
||||
|
||||
function test() {
|
||||
$f = file_get_contents('http://127.0.0.1:22350/');
|
||||
var_dump($f);
|
||||
var_dump($http_response_header);
|
||||
}
|
||||
test();
|
||||
$f = file_get_contents($uri);
|
||||
var_dump($f);
|
||||
var_dump($http_response_header);
|
||||
|
||||
http_server_kill($pid);
|
||||
?>
|
||||
|
||||
--EXPECT--
|
||||
string(4) "Body"
|
||||
array(2) {
|
||||
|
|
|
@ -3,7 +3,7 @@ http:// and ignore_errors
|
|||
--INI--
|
||||
allow_url_fopen=1
|
||||
--SKIPIF--
|
||||
<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:12342'); ?>
|
||||
<?php require 'server.inc'; http_server_skipif(); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require 'server.inc';
|
||||
|
@ -17,11 +17,11 @@ function do_test($context_options) {
|
|||
"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);
|
||||
['pid' => $pid, 'uri' => $uri] = http_server($responses, $output);
|
||||
|
||||
foreach($responses as $r) {
|
||||
|
||||
$fd = fopen('http://127.0.0.1:12342/foo/bar', 'rb', false, $context);
|
||||
$fd = fopen("$uri/foo/bar", 'rb', false, $context);
|
||||
var_dump($fd);
|
||||
|
||||
if ($fd) {
|
||||
|
@ -63,16 +63,16 @@ array(2) {
|
|||
}
|
||||
string(1) "1"
|
||||
string(%d) "GET /foo/bar HTTP/1.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
|
||||
"
|
||||
|
||||
Warning: fopen(http://127.0.0.1:12342/foo/bar): Failed to open stream: HTTP request failed! HTTP/1.1 404 Not found
|
||||
Warning: fopen(http://%s:%d/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.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
|
||||
"
|
||||
|
@ -86,7 +86,7 @@ array(2) {
|
|||
}
|
||||
string(1) "1"
|
||||
string(%d) "GET /foo/bar HTTP/1.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
|
||||
"
|
||||
|
@ -99,7 +99,7 @@ array(2) {
|
|||
}
|
||||
string(1) "2"
|
||||
string(%d) "GET /foo/bar HTTP/1.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
|
||||
"
|
||||
|
@ -113,7 +113,7 @@ array(2) {
|
|||
}
|
||||
string(1) "1"
|
||||
string(%d) "GET /foo/bar HTTP/1.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
|
||||
"
|
||||
|
@ -126,7 +126,7 @@ array(2) {
|
|||
}
|
||||
string(1) "2"
|
||||
string(%d) "GET /foo/bar HTTP/1.1
|
||||
Host: 127.0.0.1:12342
|
||||
Host: %s:%d
|
||||
Connection: close
|
||||
|
||||
"
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
function http_server_skipif($socket_string) {
|
||||
function http_server_skipif() {
|
||||
|
||||
if (!function_exists('pcntl_fork')) die('skip pcntl_fork() not available');
|
||||
if (!function_exists('posix_kill')) die('skip posix_kill() not available');
|
||||
if (!stream_socket_server($socket_string)) die('skip stream_socket_server() failed');
|
||||
if (!stream_socket_server('tcp://localhost:0')) die('skip stream_socket_server() failed');
|
||||
}
|
||||
|
||||
function http_server_init($socket_string, &$output = null) {
|
||||
function http_server_init(&$output = null) {
|
||||
pcntl_alarm(60);
|
||||
|
||||
$server = stream_socket_server($socket_string, $errno, $errstr);
|
||||
$server = stream_socket_server('tcp://localhost:0', $errno, $errstr);
|
||||
if (!$server) {
|
||||
return false;
|
||||
}
|
||||
|
@ -26,7 +26,10 @@ function http_server_init($socket_string, &$output = null) {
|
|||
if ($pid == -1) {
|
||||
die('could not fork');
|
||||
} else if ($pid) {
|
||||
return $pid;
|
||||
return [
|
||||
'pid' => $pid,
|
||||
'uri' => 'http://' . stream_socket_get_name($server, false),
|
||||
];
|
||||
}
|
||||
|
||||
return $server;
|
||||
|
@ -35,15 +38,20 @@ function http_server_init($socket_string, &$output = null) {
|
|||
/* Minimal HTTP server with predefined responses.
|
||||
*
|
||||
* $socket_string is the socket to create and listen on (e.g. tcp://127.0.0.1:1234)
|
||||
* $files is an array of files containing N responses for N expected requests. Server dies after N requests.
|
||||
* $files is an iterable of files or callable generator yielding files.
|
||||
* containing N responses for N expected requests. Server dies after N requests.
|
||||
* $output is a stream on which everything sent by clients is written to
|
||||
*/
|
||||
function http_server($socket_string, array $files, &$output = null) {
|
||||
function http_server($files, &$output = null) {
|
||||
|
||||
if (!is_resource($server = http_server_init($socket_string, $output))) {
|
||||
if (!is_resource($server = http_server_init($output))) {
|
||||
return $server;
|
||||
}
|
||||
|
||||
if (is_callable($files)) {
|
||||
$files = $files($server);
|
||||
}
|
||||
|
||||
foreach($files as $file) {
|
||||
|
||||
$sock = stream_socket_accept($server);
|
||||
|
@ -55,7 +63,7 @@ function http_server($socket_string, array $files, &$output = null) {
|
|||
|
||||
$content_length = 0;
|
||||
|
||||
stream_set_blocking($sock, 0);
|
||||
stream_set_blocking($sock, false);
|
||||
while (!feof($sock)) {
|
||||
|
||||
list($r, $w, $e) = array(array($sock), null, null);
|
||||
|
@ -73,7 +81,7 @@ function http_server($socket_string, array $files, &$output = null) {
|
|||
}
|
||||
}
|
||||
}
|
||||
stream_set_blocking($sock, 1);
|
||||
stream_set_blocking($sock, true);
|
||||
|
||||
// read content
|
||||
|
||||
|
@ -92,9 +100,9 @@ function http_server($socket_string, array $files, &$output = null) {
|
|||
exit(0);
|
||||
}
|
||||
|
||||
function http_server_sleep($socket_string, $micro_seconds = 500000)
|
||||
function http_server_sleep($micro_seconds = 500000)
|
||||
{
|
||||
if (!is_resource($server = http_server_init($socket_string, $output))) {
|
||||
if (!is_resource($server = http_server_init($output))) {
|
||||
return $server;
|
||||
}
|
||||
|
||||
|
@ -110,9 +118,7 @@ function http_server_sleep($socket_string, $micro_seconds = 500000)
|
|||
exit(0);
|
||||
}
|
||||
|
||||
function http_server_kill($pid) {
|
||||
function http_server_kill(int $pid) {
|
||||
posix_kill($pid, SIGTERM);
|
||||
pcntl_waitpid($pid, $status);
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -5,20 +5,18 @@ http-stream test
|
|||
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
|
||||
if (!extension_loaded("dom")) die("skip dom extension is not present");
|
||||
require __DIR__.'/../http/server.inc';
|
||||
http_server_skipif('tcp://127.0.0.1:12342');
|
||||
?>
|
||||
http_server_skipif();
|
||||
--INI--
|
||||
allow_url_fopen=1
|
||||
--FILE--
|
||||
<?php
|
||||
require __DIR__.'/../http/server.inc';
|
||||
|
||||
$pid = http_server("tcp://127.0.0.1:12342", [__DIR__."/news.rss"]);
|
||||
['pid' => $pid, 'uri' => $uri] = http_server([__DIR__."/news.rss"]);
|
||||
|
||||
$d = new DomDocument;
|
||||
$e = $d->load("http://127.0.0.1:12342/news.rss");
|
||||
$e = $d->load("$uri/news.rss");
|
||||
echo "ALIVE\n";
|
||||
http_server_kill($pid);
|
||||
?>
|
||||
--EXPECT--
|
||||
ALIVE
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue