1--TEST--
2http:// and ignore_errors
3--INI--
4allow_url_fopen=1
5--SKIPIF--
6<?php require 'server.inc'; http_server_skipif(); ?>
7--FILE--
8<?php
9require 'server.inc';
10
11function do_test($context_options) {
12
13    $context = stream_context_create(array('http' => $context_options));
14
15    $responses = array(
16        "data://text/plain,HTTP/1.1 200 Ok\r\nX-Foo: bar\r\n\r\n1",
17        "data://text/plain,HTTP/1.1 404 Not found\r\nX-bar: baz\r\n\r\n2",
18    );
19
20    ['pid' => $pid, 'uri' => $uri] = http_server($responses, $output);
21
22    foreach($responses as $r) {
23
24        $fd = fopen("$uri/foo/bar", 'rb', false, $context);
25        var_dump($fd);
26
27        if ($fd) {
28            $meta_data = stream_get_meta_data($fd);
29            var_dump($meta_data['wrapper_data']);
30
31            var_dump(stream_get_contents($fd));
32        }
33
34        fseek($output, 0, SEEK_SET);
35        var_dump(stream_get_contents($output));
36        fseek($output, 0, SEEK_SET);
37    }
38
39    http_server_kill($pid);
40}
41
42echo "-- Test: requests without ignore_errors --\n";
43
44do_test(array());
45
46echo "-- Test: requests with ignore_errors --\n";
47
48do_test(array('ignore_errors' => true));
49
50echo "-- Test: requests with ignore_errors (2) --\n";
51
52do_test(array('ignore_errors' => 1));
53
54?>
55--EXPECTF--
56-- Test: requests without ignore_errors --
57resource(%d) of type (stream)
58array(2) {
59  [0]=>
60  string(15) "HTTP/1.1 200 Ok"
61  [1]=>
62  string(10) "X-Foo: bar"
63}
64string(1) "1"
65string(%d) "GET /foo/bar HTTP/1.1
66Host: %s:%d
67Connection: close
68
69"
70
71Warning: fopen(http://%s:%d/foo/bar): Failed to open stream: HTTP request failed! HTTP/1.1 404 Not found
72 in %s on line %d
73bool(false)
74string(%d) "GET /foo/bar HTTP/1.1
75Host: %s:%d
76Connection: close
77
78"
79-- Test: requests with ignore_errors --
80resource(%d) of type (stream)
81array(2) {
82  [0]=>
83  string(15) "HTTP/1.1 200 Ok"
84  [1]=>
85  string(10) "X-Foo: bar"
86}
87string(1) "1"
88string(%d) "GET /foo/bar HTTP/1.1
89Host: %s:%d
90Connection: close
91
92"
93resource(%d) of type (stream)
94array(2) {
95  [0]=>
96  string(22) "HTTP/1.1 404 Not found"
97  [1]=>
98  string(10) "X-bar: baz"
99}
100string(1) "2"
101string(%d) "GET /foo/bar HTTP/1.1
102Host: %s:%d
103Connection: close
104
105"
106-- Test: requests with ignore_errors (2) --
107resource(%d) of type (stream)
108array(2) {
109  [0]=>
110  string(15) "HTTP/1.1 200 Ok"
111  [1]=>
112  string(10) "X-Foo: bar"
113}
114string(1) "1"
115string(%d) "GET /foo/bar HTTP/1.1
116Host: %s:%d
117Connection: close
118
119"
120resource(%d) of type (stream)
121array(2) {
122  [0]=>
123  string(22) "HTTP/1.1 404 Not found"
124  [1]=>
125  string(10) "X-bar: baz"
126}
127string(1) "2"
128string(%d) "GET /foo/bar HTTP/1.1
129Host: %s:%d
130Connection: close
131
132"
133