|
| 1 | +--TEST-- |
| 2 | +POST Content-Type and Content-Length headers removed on redirect except for 307/308 |
| 3 | +--SKIPIF-- |
| 4 | +<?php |
| 5 | +require_once 'server.inc'; |
| 6 | +http_server_skipif(); |
| 7 | +?> |
| 8 | +--INI-- |
| 9 | +allow_url_fopen=1 |
| 10 | +--FILE-- |
| 11 | +<?php |
| 12 | +require_once 'server.inc'; |
| 13 | + |
| 14 | +$status_codes = [301, 302, 303, 307, 308]; |
| 15 | + |
| 16 | +$responses = []; |
| 17 | +foreach ($status_codes as $code) { |
| 18 | + $responses[] = "data://text/plain," |
| 19 | + . "HTTP/1.1 $code Redirect\r\n" |
| 20 | + . "Location: /$code-redirected\r\n" |
| 21 | + . "Content-Length: 0\r\n" |
| 22 | + . "\r\n"; |
| 23 | + |
| 24 | + $responses[] = "data://text/plain," |
| 25 | + . "HTTP/1.1 200 OK\r\n" |
| 26 | + . "Content-Length: 0\r\n" |
| 27 | + . "\r\n"; |
| 28 | +} |
| 29 | + |
| 30 | +$server = http_server($responses, $output); |
| 31 | + |
| 32 | +$context = stream_context_create([ |
| 33 | + 'http' => [ |
| 34 | + 'method' => 'POST', |
| 35 | + 'content' => 'test=data', |
| 36 | + 'follow_location' => 1, |
| 37 | + 'max_redirects' => 3, |
| 38 | + 'header' => |
| 39 | + "Content-Type: application/x-www-form-urlencoded\r\n" . |
| 40 | + "Content-Length: 9\r\n", |
| 41 | + ], |
| 42 | +]); |
| 43 | + |
| 44 | +foreach ($status_codes as $code) { |
| 45 | + file_get_contents($server['uri'], false, $context); |
| 46 | +} |
| 47 | + |
| 48 | +http_server_kill($server['pid']); |
| 49 | + |
| 50 | +rewind($output); |
| 51 | +$contents = stream_get_contents($output); |
| 52 | + |
| 53 | +foreach ($status_codes as $code) { |
| 54 | + if (!preg_match("~(GET|POST) /$code-redirected .*?\r\n\r\n~s", $contents, $matches)) { |
| 55 | + die("fail redirect request for $code not found\n"); |
| 56 | + } |
| 57 | + echo "Redirect request for $code has Content-Type: "; |
| 58 | + var_dump(stripos($matches[0], 'content-type') !== false); |
| 59 | + echo "Redirect request for $code has Content-Length: "; |
| 60 | + var_dump(stripos($matches[0], 'content-length') !== false); |
| 61 | +} |
| 62 | + |
| 63 | +?> |
| 64 | +--EXPECT-- |
| 65 | +Redirect request for 301 has Content-Type: bool(false) |
| 66 | +Redirect request for 301 has Content-Length: bool(false) |
| 67 | +Redirect request for 302 has Content-Type: bool(false) |
| 68 | +Redirect request for 302 has Content-Length: bool(false) |
| 69 | +Redirect request for 303 has Content-Type: bool(false) |
| 70 | +Redirect request for 303 has Content-Length: bool(false) |
| 71 | +Redirect request for 307 has Content-Type: bool(true) |
| 72 | +Redirect request for 307 has Content-Length: bool(true) |
| 73 | +Redirect request for 308 has Content-Type: bool(true) |
| 74 | +Redirect request for 308 has Content-Length: bool(true) |
0 commit comments