Skip to content

Commit df153ce

Browse files
authored
Make distinction between 0 or false for maxAge (#62)
Make distinction between 0 or null for maxAge
1 parent 470eacc commit df153ce

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/Asm89/Stack/CorsService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ private function buildPreflightCheckResponse(Request $request)
116116

117117
$response->headers->set('Access-Control-Allow-Origin', $request->headers->get('Origin'));
118118

119-
if ($this->options['maxAge']) {
119+
if ($this->options['maxAge'] !== null) {
120120
$response->headers->set('Access-Control-Max-Age', $this->options['maxAge']);
121121
}
122122

test/Asm89/Stack/CorsTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,33 @@ public function it_sets_max_age_when_set()
402402
$this->assertEquals(42, $response->headers->get('Access-Control-Max-Age'));
403403
}
404404

405+
/**
406+
* @test
407+
*/
408+
public function it_sets_max_age_when_zero()
409+
{
410+
$app = $this->createStackedApp(array('maxAge' => 0));
411+
$request = $this->createValidPreflightRequest();
412+
413+
$response = $app->handle($request);
414+
415+
$this->assertTrue($response->headers->has('Access-Control-Max-Age'));
416+
$this->assertEquals(0, $response->headers->get('Access-Control-Max-Age'));
417+
}
418+
419+
/**
420+
* @test
421+
*/
422+
public function it_doesnt_set_max_age_when_false()
423+
{
424+
$app = $this->createStackedApp(array('maxAge' => null));
425+
$request = $this->createValidPreflightRequest();
426+
427+
$response = $app->handle($request);
428+
429+
$this->assertFalse($response->headers->has('Access-Control-Max-Age'));
430+
}
431+
405432
/**
406433
* @test
407434
*/

0 commit comments

Comments
 (0)