1--TEST-- 2Bug #38802 (ignore_errors and max_redirects) 3--INI-- 4allow_url_fopen=1 5--SKIPIF-- 6<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:12342'); ?> 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.0 302 Moved Temporarily\r\nLocation: http://127.0.0.1:12342/foo/bar2\r\n\r\n1", 17 "data://text/plain,HTTP/1.0 301 Moved Permanently\r\nLocation: http://127.0.0.1:12342/foo/bar3\r\n\r\n", 18 "data://text/plain,HTTP/1.0 302 Moved Temporarily\r\nLocation: http://127.0.0.1:12342/foo/bar4\r\n\r\n3", 19 "data://text/plain,HTTP/1.0 200 OK\r\n\r\ndone.", 20 ); 21 22 $pid = http_server("tcp://127.0.0.1:12342", $responses, $output); 23 24 $fd = fopen('http://127.0.0.1:12342/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 37 http_server_kill($pid); 38} 39 40echo "-- Test: follow all redirections --\n"; 41 42do_test(array(), 4); 43 44echo "-- Test: fail after 2 redirections --\n"; 45 46do_test(array('max_redirects' => 2), 2); 47 48echo "-- Test: fail at first redirection --\n"; 49 50do_test(array('max_redirects' => 0), 1); 51 52echo "-- Test: fail at first redirection (2) --\n"; 53 54do_test(array('max_redirects' => 1), 1); 55 56echo "-- Test: return at first redirection --\n"; 57 58do_test(array('max_redirects' => 0, 'ignore_errors' => 1), 1); 59 60echo "-- Test: return at first redirection (2) --\n"; 61 62do_test(array('max_redirects' => 1, 'ignore_errors' => 1), 1); 63 64echo "-- Test: return at second redirection --\n"; 65 66do_test(array('max_redirects' => 2, 'ignore_errors' => 1), 2); 67 68?> 69--EXPECTF-- 70-- Test: follow all redirections -- 71resource(%d) of type (stream) 72array(7) { 73 [0]=> 74 string(30) "HTTP/1.0 302 Moved Temporarily" 75 [1]=> 76 string(41) "Location: http://127.0.0.1:12342/foo/bar2" 77 [2]=> 78 string(30) "HTTP/1.0 301 Moved Permanently" 79 [3]=> 80 string(41) "Location: http://127.0.0.1:12342/foo/bar3" 81 [4]=> 82 string(30) "HTTP/1.0 302 Moved Temporarily" 83 [5]=> 84 string(41) "Location: http://127.0.0.1:12342/foo/bar4" 85 [6]=> 86 string(15) "HTTP/1.0 200 OK" 87} 88string(5) "done." 89string(195) "GET /foo/bar HTTP/1.0 90Host: 127.0.0.1:12342 91 92GET /foo/bar2 HTTP/1.0 93Host: 127.0.0.1:12342 94 95GET /foo/bar3 HTTP/1.0 96Host: 127.0.0.1:12342 97 98GET /foo/bar4 HTTP/1.0 99Host: 127.0.0.1:12342 100 101" 102-- Test: fail after 2 redirections -- 103 104Warning: fopen(http://127.0.0.1:12342/foo/bar): failed to open stream: Redirection limit reached, aborting in %s 105bool(false) 106string(97) "GET /foo/bar HTTP/1.0 107Host: 127.0.0.1:12342 108 109GET /foo/bar2 HTTP/1.0 110Host: 127.0.0.1:12342 111 112" 113-- Test: fail at first redirection -- 114 115Warning: fopen(http://127.0.0.1:12342/foo/bar): failed to open stream: Redirection limit reached, aborting in %s 116bool(false) 117string(48) "GET /foo/bar HTTP/1.0 118Host: 127.0.0.1:12342 119 120" 121-- Test: fail at first redirection (2) -- 122 123Warning: fopen(http://127.0.0.1:12342/foo/bar): failed to open stream: Redirection limit reached, aborting in %s 124bool(false) 125string(48) "GET /foo/bar HTTP/1.0 126Host: 127.0.0.1:12342 127 128" 129-- Test: return at first redirection -- 130resource(%d) of type (stream) 131array(2) { 132 [0]=> 133 string(30) "HTTP/1.0 302 Moved Temporarily" 134 [1]=> 135 string(41) "Location: http://127.0.0.1:12342/foo/bar2" 136} 137string(1) "1" 138string(48) "GET /foo/bar HTTP/1.0 139Host: 127.0.0.1:12342 140 141" 142-- Test: return at first redirection (2) -- 143resource(%d) of type (stream) 144array(2) { 145 [0]=> 146 string(30) "HTTP/1.0 302 Moved Temporarily" 147 [1]=> 148 string(41) "Location: http://127.0.0.1:12342/foo/bar2" 149} 150string(1) "1" 151string(48) "GET /foo/bar HTTP/1.0 152Host: 127.0.0.1:12342 153 154" 155-- Test: return at second redirection -- 156resource(%d) of type (stream) 157array(4) { 158 [0]=> 159 string(30) "HTTP/1.0 302 Moved Temporarily" 160 [1]=> 161 string(41) "Location: http://127.0.0.1:12342/foo/bar2" 162 [2]=> 163 string(30) "HTTP/1.0 301 Moved Permanently" 164 [3]=> 165 string(41) "Location: http://127.0.0.1:12342/foo/bar3" 166} 167string(0) "" 168string(97) "GET /foo/bar HTTP/1.0 169Host: 127.0.0.1:12342 170 171GET /foo/bar2 HTTP/1.0 172Host: 127.0.0.1:12342 173 174" 175