xref: /PHP-8.2/ext/standard/tests/http/bug67430.phpt (revision 1ede3137)
1--TEST--
2Bug #67430 (http:// wrapper doesn't follow 308 redirects)
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($follow) {
12  $options = [
13    'http' => [
14      'method' => 'POST',
15      'follow_location' => $follow,
16    ],
17  ];
18
19  $ctx = stream_context_create($options);
20
21  $responses = [
22    "data://text/plain,HTTP/1.1 308\r\nLocation: /foo\r\n\r\n",
23    "data://text/plain,HTTP/1.1 200\r\nConnection: close\r\n\r\n",
24  ];
25  ['pid' => $pid, 'uri' => $uri] = http_server($responses, $output);
26
27  $fd = fopen($uri, 'rb', false, $ctx);
28  fseek($output, 0, SEEK_SET);
29  echo stream_get_contents($output);
30
31  http_server_kill($pid);
32}
33
34do_test(true);
35do_test(false);
36
37?>
38Done
39--EXPECTF--
40POST / HTTP/1.1
41Host: %s:%d
42Connection: close
43
44POST /foo HTTP/1.1
45Host: %s:%d
46Connection: close
47
48POST / HTTP/1.1
49Host: %s:%d
50Connection: close
51
52Done
53