Skip to content

Commit 6f6a23e

Browse files
authored
Add CORS headers on non-Origin requests (#73)
* Always run CORS on actual requests * Add test that it runs always
1 parent 0d1e277 commit 6f6a23e

File tree

2 files changed

+4
-11
lines changed

2 files changed

+4
-11
lines changed

src/Cors.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ public function __construct(HttpKernelInterface $app, array $options = array())
4545

4646
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
4747
{
48-
if (!$this->cors->isCorsRequest($request)) {
49-
return $this->app->handle($request, $type, $catch);
50-
}
51-
5248
if ($this->cors->isPreflightRequest($request)) {
5349
return $this->cors->handlePreflightRequest($request);
5450
}

tests/CorsTest.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,20 @@ class CorsTest extends TestCase
2222
/**
2323
* @test
2424
*/
25-
public function it_does_not_modify_on_a_request_without_origin()
25+
public function it_does_modify_on_a_request_without_origin()
2626
{
2727
$app = $this->createStackedApp();
2828
$unmodifiedResponse = new Response();
2929

3030
$response = $app->handle(new Request());
3131

32-
$this->assertEquals($unmodifiedResponse->headers, $response->headers);
32+
$this->assertEquals('localhost', $response->headers->get('Access-Control-Allow-Origin'));
3333
}
3434

35-
3635
/**
3736
* @test
3837
*/
39-
public function it_does_not_modify_on_a_request_with_same_origin()
38+
public function it_does_modify_on_a_request_with_same_origin()
4039
{
4140
$app = $this->createStackedApp(array('allowedOrigins' => array('*')));
4241
$unmodifiedResponse = new Response();
@@ -45,10 +44,8 @@ public function it_does_not_modify_on_a_request_with_same_origin()
4544
$request->headers->set('Host', 'foo.com');
4645
$request->headers->set('Origin', 'http://foo.com');
4746
$response = $app->handle($request);
48-
$unmodifiedResponse->headers->date = '';
49-
$response->headers->date = '';
5047

51-
$this->assertEquals($unmodifiedResponse->headers, $response->headers);
48+
$this->assertEquals('*', $response->headers->get('Access-Control-Allow-Origin'));
5249
}
5350

5451
/**

0 commit comments

Comments
 (0)