summaryrefslogtreecommitdiff
path: root/ext/standard/tests/http/ignore_errors.phpt
blob: ab5421890bccf3190a61957a4f660a66496b1bba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
--TEST--
http:// and ignore_errors
--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 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",
	);

	$pid = http_server("tcp://127.0.0.1:12342", $responses, $output);

	foreach($responses as $r) {

		$fd = fopen('http://127.0.0.1:12342/foo/bar', 'rb', false, $context);
		var_dump($fd);

		if ($fd) {
			$meta_data = stream_get_meta_data($fd);
			var_dump($meta_data['wrapper_data']);
	
			var_dump(stream_get_contents($fd));
		}

		fseek($output, 0, SEEK_SET);
		var_dump(stream_get_contents($output));
		fseek($output, 0, SEEK_SET);
	}

	http_server_kill($pid);
}

echo "-- Test: requests without ignore_errors --\n";

do_test(array());

echo "-- Test: requests with ignore_errors --\n";

do_test(array('ignore_errors' => true));

echo "-- Test: requests with ignore_errors (2) --\n";

do_test(array('ignore_errors' => 1));

?>
--EXPECTF--
-- Test: requests without ignore_errors --
resource(%d) of type (stream)
array(2) {
  [0]=>
  string(15) "HTTP/1.0 200 Ok"
  [1]=>
  string(10) "X-Foo: bar"
}
string(1) "1"
string(48) "GET /foo/bar HTTP/1.0
Host: 127.0.0.1:12342

"

Warning: fopen(http://127.0.0.1:12342/foo/bar): failed to open stream: HTTP request failed! HTTP/1.0 404 Not found
 in %s on line %d
bool(false)
string(48) "GET /foo/bar HTTP/1.0
Host: 127.0.0.1:12342

"
-- Test: requests with ignore_errors --
resource(%d) of type (stream)
array(2) {
  [0]=>
  string(15) "HTTP/1.0 200 Ok"
  [1]=>
  string(10) "X-Foo: bar"
}
string(1) "1"
string(48) "GET /foo/bar HTTP/1.0
Host: 127.0.0.1:12342

"
resource(%d) of type (stream)
array(2) {
  [0]=>
  string(22) "HTTP/1.0 404 Not found"
  [1]=>
  string(10) "X-bar: baz"
}
string(1) "2"
string(48) "GET /foo/bar HTTP/1.0
Host: 127.0.0.1:12342

"
-- Test: requests with ignore_errors (2) --
resource(%d) of type (stream)
array(2) {
  [0]=>
  string(15) "HTTP/1.0 200 Ok"
  [1]=>
  string(10) "X-Foo: bar"
}
string(1) "1"
string(48) "GET /foo/bar HTTP/1.0
Host: 127.0.0.1:12342

"
resource(%d) of type (stream)
array(2) {
  [0]=>
  string(22) "HTTP/1.0 404 Not found"
  [1]=>
  string(10) "X-bar: baz"
}
string(1) "2"
string(48) "GET /foo/bar HTTP/1.0
Host: 127.0.0.1:12342

"