@@ -269,23 +269,84 @@ public function testRedirectSetsDefaultCodeAndLocationHeader()
269269 $ this ->assertSame (302 , $ response ->getStatusCode ());
270270 }
271271
272- public function testRedirectSetsCode ()
273- {
274- $ response = new Response (new App ());
272+ /**
273+ * @dataProvider provideForRedirect
274+ */
275+ public function testRedirect (
276+ string $ server ,
277+ string $ protocol ,
278+ string $ method ,
279+ ?int $ code ,
280+ int $ expectedCode
281+ ) {
282+ $ _SERVER ['SERVER_SOFTWARE ' ] = $ server ;
283+ $ _SERVER ['SERVER_PROTOCOL ' ] = $ protocol ;
284+ $ _SERVER ['REQUEST_METHOD ' ] = $ method ;
275285
276- $ response ->redirect ('example.com ' , 'auto ' , 307 );
286+ $ response = new Response (new App ());
287+ $ response ->redirect ('example.com ' , 'auto ' , $ code );
277288
278289 $ this ->assertTrue ($ response ->hasHeader ('location ' ));
279290 $ this ->assertSame ('example.com ' , $ response ->getHeaderLine ('Location ' ));
280- $ this ->assertSame (307 , $ response ->getStatusCode ());
291+ $ this ->assertSame ($ expectedCode , $ response ->getStatusCode ());
292+ }
293+
294+ public function provideForRedirect ()
295+ {
296+ yield from [
297+ ['Apache/2.4.17 ' , 'HTTP/1.1 ' , 'GET ' , null , 302 ],
298+ ['Apache/2.4.17 ' , 'HTTP/1.1 ' , 'GET ' , 307 , 307 ],
299+ ['Apache/2.4.17 ' , 'HTTP/1.1 ' , 'GET ' , 302 , 302 ],
300+ ['Apache/2.4.17 ' , 'HTTP/1.1 ' , 'POST ' , null , 303 ],
301+ ['Apache/2.4.17 ' , 'HTTP/1.1 ' , 'POST ' , 307 , 307 ],
302+ ['Apache/2.4.17 ' , 'HTTP/1.1 ' , 'POST ' , 302 , 302 ],
303+ ['Apache/2.4.17 ' , 'HTTP/1.1 ' , 'HEAD ' , null , 307 ],
304+ ['Apache/2.4.17 ' , 'HTTP/1.1 ' , 'HEAD ' , 307 , 307 ],
305+ ['Apache/2.4.17 ' , 'HTTP/1.1 ' , 'HEAD ' , 302 , 302 ],
306+ ['Apache/2.4.17 ' , 'HTTP/1.1 ' , 'OPTIONS ' , null , 307 ],
307+ ['Apache/2.4.17 ' , 'HTTP/1.1 ' , 'OPTIONS ' , 307 , 307 ],
308+ ['Apache/2.4.17 ' , 'HTTP/1.1 ' , 'OPTIONS ' , 302 , 302 ],
309+ ['Apache/2.4.17 ' , 'HTTP/1.1 ' , 'PUT ' , null , 303 ],
310+ ['Apache/2.4.17 ' , 'HTTP/1.1 ' , 'PUT ' , 307 , 307 ],
311+ ['Apache/2.4.17 ' , 'HTTP/1.1 ' , 'PUT ' , 302 , 302 ],
312+ ['Apache/2.4.17 ' , 'HTTP/1.1 ' , 'DELETE ' , null , 303 ],
313+ ['Apache/2.4.17 ' , 'HTTP/1.1 ' , 'DELETE ' , 307 , 307 ],
314+ ['Apache/2.4.17 ' , 'HTTP/1.1 ' , 'DELETE ' , 302 , 302 ],
315+ ];
281316 }
282317
283- public function testRedirectWithIIS ()
284- {
318+ /**
319+ * @dataProvider provideForRedirectWithIIS
320+ */
321+ public function testRedirectWithIIS (
322+ string $ protocol ,
323+ string $ method ,
324+ ?int $ code ,
325+ int $ expectedCode
326+ ) {
285327 $ _SERVER ['SERVER_SOFTWARE ' ] = 'Microsoft-IIS ' ;
286- $ response = new Response (new App ());
287- $ response ->redirect ('example.com ' , 'auto ' , 307 );
328+ $ _SERVER ['SERVER_PROTOCOL ' ] = 'HTTP/1.1 ' ;
329+ $ _SERVER ['REQUEST_METHOD ' ] = 'POST ' ;
330+
331+ $ response = new Response (new App ());
332+ $ response ->redirect ('example.com ' , 'auto ' , $ code );
333+
288334 $ this ->assertSame ('0;url=example.com ' , $ response ->getHeaderLine ('Refresh ' ));
335+ $ this ->assertSame ($ expectedCode , $ response ->getStatusCode ());
336+
337+ unset($ _SERVER ['SERVER_SOFTWARE ' ]);
338+ }
339+
340+ public function provideForRedirectWithIIS ()
341+ {
342+ yield from [
343+ ['HTTP/1.1 ' , 'GET ' , null , 302 ],
344+ ['HTTP/1.1 ' , 'GET ' , 307 , 307 ],
345+ ['HTTP/1.1 ' , 'GET ' , 302 , 302 ],
346+ ['HTTP/1.1 ' , 'POST ' , null , 302 ],
347+ ['HTTP/1.1 ' , 'POST ' , 307 , 307 ],
348+ ['HTTP/1.1 ' , 'POST ' , 302 , 302 ],
349+ ];
289350 }
290351
291352 public function testSetCookieFails ()
@@ -458,7 +519,7 @@ public function testMisbehaving()
458519 $ response ->getStatusCode ();
459520 }
460521
461- public function testTemporaryRedirect11 ()
522+ public function testTemporaryRedirectHTTP11 ()
462523 {
463524 $ _SERVER ['SERVER_PROTOCOL ' ] = 'HTTP/1.1 ' ;
464525 $ _SERVER ['REQUEST_METHOD ' ] = 'POST ' ;
@@ -470,7 +531,7 @@ public function testTemporaryRedirect11()
470531 $ this ->assertSame (303 , $ response ->getStatusCode ());
471532 }
472533
473- public function testTemporaryRedirectGet11 ()
534+ public function testTemporaryRedirectGetHTTP11 ()
474535 {
475536 $ _SERVER ['SERVER_PROTOCOL ' ] = 'HTTP/1.1 ' ;
476537 $ _SERVER ['REQUEST_METHOD ' ] = 'GET ' ;
@@ -479,7 +540,7 @@ public function testTemporaryRedirectGet11()
479540 $ response ->setProtocolVersion ('HTTP/1.1 ' );
480541 $ response ->redirect ('/foo ' );
481542
482- $ this ->assertSame (307 , $ response ->getStatusCode ());
543+ $ this ->assertSame (302 , $ response ->getStatusCode ());
483544 }
484545
485546 // Make sure cookies are set by RedirectResponse this way
0 commit comments