Skip to content

Commit 9e14e42

Browse files
committed
Implement redirection
1 parent 39db40f commit 9e14e42

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

src/Igorw/CgiHttpKernel/CgiHttpKernel.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,21 @@ public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQ
3535
$process->wait();
3636

3737
list($headerList, $body) = explode("\r\n\r\n", $process->getOutput());
38-
$headers = $this->getHeaderMap(explode("\n", $headerList));
38+
$headers = $this->getHeaderMap(explode("\r\n", $headerList));
3939

40-
return new Response($body, 200, $headers);
40+
$status = $this->getStatusCode($headers);
41+
42+
return new Response($body, $status, $headers);
43+
}
44+
45+
public function getStatusCode(array $headers)
46+
{
47+
if (isset($headers['Status'])) {
48+
list($code) = explode(' ', $headers['Status']);
49+
return (int) $code;
50+
}
51+
52+
return 200;
4153
}
4254

4355
public function getHeaderMap(array $headerList)

tests/Igorw/CgiHttpKernel/CgiHttpKernelTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,14 @@ public function missingFileShouldResultIn404()
3232

3333
$this->assertSame(404, $response->getStatusCode());
3434
}
35+
36+
/** @test */
37+
public function customHeadersShouldBeSent()
38+
{
39+
$request = Request::create('/redirect.php');
40+
$response = $this->kernel->handle($request);
41+
42+
$this->assertSame(302, $response->getStatusCode());
43+
$this->assertSame('/foo.php', $response->headers->get('Location'));
44+
}
3545
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
header('Location: /foo.php');

0 commit comments

Comments
 (0)