Annotation of embedaddon/php/ext/standard/tests/http/bug38802.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Bug #38802 (ignore_errors and max_redirects)
                      3: --INI--
                      4: allow_url_fopen=1
                      5: --SKIPIF--
                      6: <?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:12342'); ?>
                      7: --FILE--
                      8: <?php
                      9: require 'server.inc';
                     10: 
                     11: function 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: 
                     40: echo "-- Test: follow all redirections --\n";
                     41: 
                     42: do_test(array(), 4);
                     43: 
                     44: echo "-- Test: fail after 2 redirections --\n";
                     45: 
                     46: do_test(array('max_redirects' => 2), 2);
                     47: 
                     48: echo "-- Test: fail at first redirection --\n";
                     49: 
                     50: do_test(array('max_redirects' => 0), 1);
                     51: 
                     52: echo "-- Test: fail at first redirection (2) --\n";
                     53: 
                     54: do_test(array('max_redirects' => 1), 1);
                     55: 
                     56: echo "-- Test: return at first redirection --\n";
                     57: 
                     58: do_test(array('max_redirects' => 0, 'ignore_errors' => 1), 1);
                     59: 
                     60: echo "-- Test: return at first redirection (2) --\n";
                     61: 
                     62: do_test(array('max_redirects' => 1, 'ignore_errors' => 1), 1);
                     63: 
                     64: echo "-- Test: return at second redirection --\n";
                     65: 
                     66: do_test(array('max_redirects' => 2, 'ignore_errors' => 1), 2);
                     67: 
                     68: ?>
                     69: --EXPECTF--
                     70: -- Test: follow all redirections --
                     71: resource(%d) of type (stream)
                     72: array(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: }
                     88: string(5) "done."
                     89: string(195) "GET /foo/bar HTTP/1.0
                     90: Host: 127.0.0.1:12342
                     91: 
                     92: GET /foo/bar2 HTTP/1.0
                     93: Host: 127.0.0.1:12342
                     94: 
                     95: GET /foo/bar3 HTTP/1.0
                     96: Host: 127.0.0.1:12342
                     97: 
                     98: GET /foo/bar4 HTTP/1.0
                     99: Host: 127.0.0.1:12342
                    100: 
                    101: "
                    102: -- Test: fail after 2 redirections --
                    103: 
                    104: Warning: fopen(http://127.0.0.1:12342/foo/bar): failed to open stream: Redirection limit reached, aborting in %s
                    105: bool(false)
                    106: string(97) "GET /foo/bar HTTP/1.0
                    107: Host: 127.0.0.1:12342
                    108: 
                    109: GET /foo/bar2 HTTP/1.0
                    110: Host: 127.0.0.1:12342
                    111: 
                    112: "
                    113: -- Test: fail at first redirection --
                    114: 
                    115: Warning: fopen(http://127.0.0.1:12342/foo/bar): failed to open stream: Redirection limit reached, aborting in %s
                    116: bool(false)
                    117: string(48) "GET /foo/bar HTTP/1.0
                    118: Host: 127.0.0.1:12342
                    119: 
                    120: "
                    121: -- Test: fail at first redirection (2) --
                    122: 
                    123: Warning: fopen(http://127.0.0.1:12342/foo/bar): failed to open stream: Redirection limit reached, aborting in %s
                    124: bool(false)
                    125: string(48) "GET /foo/bar HTTP/1.0
                    126: Host: 127.0.0.1:12342
                    127: 
                    128: "
                    129: -- Test: return at first redirection --
                    130: resource(%d) of type (stream)
                    131: array(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: }
                    137: string(1) "1"
                    138: string(48) "GET /foo/bar HTTP/1.0
                    139: Host: 127.0.0.1:12342
                    140: 
                    141: "
                    142: -- Test: return at first redirection (2) --
                    143: resource(%d) of type (stream)
                    144: array(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: }
                    150: string(1) "1"
                    151: string(48) "GET /foo/bar HTTP/1.0
                    152: Host: 127.0.0.1:12342
                    153: 
                    154: "
                    155: -- Test: return at second redirection --
                    156: resource(%d) of type (stream)
                    157: array(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: }
                    167: string(0) ""
                    168: string(97) "GET /foo/bar HTTP/1.0
                    169: Host: 127.0.0.1:12342
                    170: 
                    171: GET /foo/bar2 HTTP/1.0
                    172: Host: 127.0.0.1:12342
                    173: 
                    174: "

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>