diff --git a/ext/soap/tests/bug47021.phpt b/ext/soap/tests/bug47021.phpt index 757e74ef15e..b05505dd19e 100644 --- a/ext/soap/tests/bug47021.phpt +++ b/ext/soap/tests/bug47021.phpt @@ -4,12 +4,9 @@ Bug #47021 SoapClient (SoapClient stumbles over WSDL delivered with "Transfer-En soap.wsdl_cache_enabled=0 --SKIPIF-- +require __DIR__.'/../../standard/tests/http/server.inc'; +http_server_skipif(); --FILE-- $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) diff --git a/ext/standard/tests/http/CONFLICTS b/ext/standard/tests/http/CONFLICTS deleted file mode 100644 index 254defddb53..00000000000 --- a/ext/standard/tests/http/CONFLICTS +++ /dev/null @@ -1 +0,0 @@ -server diff --git a/ext/standard/tests/http/bug38802.phpt b/ext/standard/tests/http/bug38802.phpt index dc00a834c18..1d7dc4d2d99 100644 --- a/ext/standard/tests/http/bug38802.phpt +++ b/ext/standard/tests/http/bug38802.phpt @@ -3,25 +3,27 @@ Bug #38802 (ignore_errors and max_redirects) --INI-- allow_url_fopen=1 --SKIPIF-- - + $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 " diff --git a/ext/standard/tests/http/bug43510.phpt b/ext/standard/tests/http/bug43510.phpt index 45ba4fb20f4..bfb90e4d747 100644 --- a/ext/standard/tests/http/bug43510.phpt +++ b/ext/standard/tests/http/bug43510.phpt @@ -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-- - + --FILE-- $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); diff --git a/ext/standard/tests/http/bug47021.phpt b/ext/standard/tests/http/bug47021.phpt index b3acd1bc3ad..326eceb687a 100644 --- a/ext/standard/tests/http/bug47021.phpt +++ b/ext/standard/tests/http/bug47021.phpt @@ -3,7 +3,7 @@ Bug #47021 (SoapClient stumbles over WSDL delivered with "Transfer-Encoding: chu --INI-- allow_url_fopen=1 --SKIPIF-- - + --FILE-- $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); diff --git a/ext/standard/tests/http/bug48929.phpt b/ext/standard/tests/http/bug48929.phpt index fad8775b6a8..256b242f769 100644 --- a/ext/standard/tests/http/bug48929.phpt +++ b/ext/standard/tests/http/bug48929.phpt @@ -3,7 +3,7 @@ Bug #48929 (duplicate \r\n sent after last header line) --INI-- allow_url_fopen=1 --SKIPIF-- - + --FILE-- $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 diff --git a/ext/standard/tests/http/bug53198.phpt b/ext/standard/tests/http/bug53198.phpt index da2a4cf15f7..1d662184781 100644 --- a/ext/standard/tests/http/bug53198.phpt +++ b/ext/standard/tests/http/bug53198.phpt @@ -1,7 +1,7 @@ --TEST-- Bug #53198 (From: header cannot be changed with ini_set) --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 " diff --git a/ext/standard/tests/http/bug60570.phpt b/ext/standard/tests/http/bug60570.phpt index 98a6bf0d3bf..7b62bdaf0b3 100644 --- a/ext/standard/tests/http/bug60570.phpt +++ b/ext/standard/tests/http/bug60570.phpt @@ -1,7 +1,7 @@ --TEST-- Bug #60570 (Stream context leaks when http request fails) --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) diff --git a/ext/standard/tests/http/bug61548.phpt b/ext/standard/tests/http/bug61548.phpt index 24e709bf362..5f21b3769dd 100644 --- a/ext/standard/tests/http/bug61548.phpt +++ b/ext/standard/tests/http/bug61548.phpt @@ -3,7 +3,7 @@ Bug #61548 (content-type must appear at the end of headers) --INI-- allow_url_fopen=1 --SKIPIF-- - + --FILE-- $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 diff --git a/ext/standard/tests/http/bug65634.phpt b/ext/standard/tests/http/bug65634.phpt index 2d2b13989e5..196b6aa0e0b 100644 --- a/ext/standard/tests/http/bug65634.phpt +++ b/ext/standard/tests/http/bug65634.phpt @@ -3,7 +3,7 @@ Bug #65634 (HTTP wrapper is very slow with protocol_version 1.1) --INI-- allow_url_fopen=1 --SKIPIF-- - + --FILE-- $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 diff --git a/ext/standard/tests/http/bug67430.phpt b/ext/standard/tests/http/bug67430.phpt index cf8db65cf16..e72e419fc02 100644 --- a/ext/standard/tests/http/bug67430.phpt +++ b/ext/standard/tests/http/bug67430.phpt @@ -3,7 +3,7 @@ Bug #67430 (http:// wrapper doesn't follow 308 redirects) --INI-- allow_url_fopen=1 --SKIPIF-- - + --FILE-- $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 diff --git a/ext/standard/tests/http/bug69337.phpt b/ext/standard/tests/http/bug69337.phpt index 7136ff474d3..051108a0948 100644 --- a/ext/standard/tests/http/bug69337.phpt +++ b/ext/standard/tests/http/bug69337.phpt @@ -1,7 +1,7 @@ --TEST-- Bug #69337 (Stream context leaks when http request fails) --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) diff --git a/ext/standard/tests/http/bug73297.phpt b/ext/standard/tests/http/bug73297.phpt index 0b0e02f3fd0..a632ff4170e 100644 --- a/ext/standard/tests/http/bug73297.phpt +++ b/ext/standard/tests/http/bug73297.phpt @@ -3,7 +3,7 @@ Bug #73297 (Ignore 100 Continue returned by HTTP/1.1 servers) --INI-- allow_url_fopen=1 --SKIPIF-- - + --FILE-- $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 diff --git a/ext/standard/tests/http/bug75535.phpt b/ext/standard/tests/http/bug75535.phpt index 236a96820c8..7b015890d2f 100644 --- a/ext/standard/tests/http/bug75535.phpt +++ b/ext/standard/tests/http/bug75535.phpt @@ -1,7 +1,7 @@ --TEST-- Bug #75535: Inappropriately parsing HTTP response leads to PHP segment fault --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) { diff --git a/ext/standard/tests/http/bug75981.phpt b/ext/standard/tests/http/bug75981.phpt index 52a560cfbc2..078f276ff98 100644 --- a/ext/standard/tests/http/bug75981.phpt +++ b/ext/standard/tests/http/bug75981.phpt @@ -3,7 +3,7 @@ Bug #75981 (stack-buffer-overflow while parsing HTTP response) --INI-- allow_url_fopen=1 --SKIPIF-- - + --FILE-- $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); diff --git a/ext/standard/tests/http/bug76342.phpt b/ext/standard/tests/http/bug76342.phpt index 10de23fdf30..f1464417f98 100644 --- a/ext/standard/tests/http/bug76342.phpt +++ b/ext/standard/tests/http/bug76342.phpt @@ -3,7 +3,7 @@ Bug #76342 (file_get_contents waits twice specified timeout) --INI-- allow_url_fopen=1 --SKIPIF-- - + --FILE-- $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 diff --git a/ext/standard/tests/http/bug79265.phpt b/ext/standard/tests/http/bug79265.phpt index 25efdd089a1..c100b9963a4 100644 --- a/ext/standard/tests/http/bug79265.phpt +++ b/ext/standard/tests/http/bug79265.phpt @@ -3,7 +3,7 @@ Bug #79265 (Improper injection of Host header when using fopen for http requests --INI-- allow_url_fopen=1 --SKIPIF-- - + --FILE-- $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 diff --git a/ext/standard/tests/http/bug79265_2.phpt b/ext/standard/tests/http/bug79265_2.phpt index 0cdde105015..a7c27bada92 100644 --- a/ext/standard/tests/http/bug79265_2.phpt +++ b/ext/standard/tests/http/bug79265_2.phpt @@ -3,7 +3,7 @@ Bug #79265 variation: "host:" not at start of header --INI-- allow_url_fopen=1 --SKIPIF-- - + --FILE-- $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 diff --git a/ext/standard/tests/http/http_response_header_01.phpt b/ext/standard/tests/http/http_response_header_01.phpt index 05037f24b1f..16cac9b0e17 100644 --- a/ext/standard/tests/http/http_response_header_01.phpt +++ b/ext/standard/tests/http/http_response_header_01.phpt @@ -1,7 +1,7 @@ --TEST-- $http_reponse_header (no redirect) --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) { diff --git a/ext/standard/tests/http/http_response_header_02.phpt b/ext/standard/tests/http/http_response_header_02.phpt index 873a8621a51..a35b1d308d2 100644 --- a/ext/standard/tests/http/http_response_header_02.phpt +++ b/ext/standard/tests/http/http_response_header_02.phpt @@ -1,7 +1,7 @@ --TEST-- $http_reponse_header (redirect) --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]=> diff --git a/ext/standard/tests/http/http_response_header_03.phpt b/ext/standard/tests/http/http_response_header_03.phpt index 832382de237..dde13997eee 100644 --- a/ext/standard/tests/http/http_response_header_03.phpt +++ b/ext/standard/tests/http/http_response_header_03.phpt @@ -1,7 +1,7 @@ --TEST-- $http_reponse_header (redirect + not found) --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]=> diff --git a/ext/standard/tests/http/http_response_header_04.phpt b/ext/standard/tests/http/http_response_header_04.phpt index 89a4d466fd6..c313f7a7560 100644 --- a/ext/standard/tests/http/http_response_header_04.phpt +++ b/ext/standard/tests/http/http_response_header_04.phpt @@ -1,7 +1,7 @@ --TEST-- $http_reponse_header (header with trailing whitespace) --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) { diff --git a/ext/standard/tests/http/http_response_header_05.phpt b/ext/standard/tests/http/http_response_header_05.phpt index 372de1163d0..c5fe60fa612 100644 --- a/ext/standard/tests/http/http_response_header_05.phpt +++ b/ext/standard/tests/http/http_response_header_05.phpt @@ -1,7 +1,7 @@ --TEST-- $http_reponse_header (whitespace-only "header") --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) { diff --git a/ext/standard/tests/http/ignore_errors.phpt b/ext/standard/tests/http/ignore_errors.phpt index 436fceeef90..9cd8cdc4509 100644 --- a/ext/standard/tests/http/ignore_errors.phpt +++ b/ext/standard/tests/http/ignore_errors.phpt @@ -3,7 +3,7 @@ http:// and ignore_errors --INI-- allow_url_fopen=1 --SKIPIF-- - + --FILE-- $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 " diff --git a/ext/standard/tests/http/server.inc b/ext/standard/tests/http/server.inc index 81cc131a8a5..5c636705e8c 100644 --- a/ext/standard/tests/http/server.inc +++ b/ext/standard/tests/http/server.inc @@ -1,16 +1,16 @@ - $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); } - -?> diff --git a/ext/standard/tests/network/http-stream.phpt b/ext/standard/tests/network/http-stream.phpt index 45c5cb636b7..4c207ade770 100644 --- a/ext/standard/tests/network/http-stream.phpt +++ b/ext/standard/tests/network/http-stream.phpt @@ -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-- $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