Skip to content
This repository has been archived by the owner on Jun 11, 2021. It is now read-only.

Commit

Permalink
Return empty response for 204 preflight requests
Browse files Browse the repository at this point in the history
  • Loading branch information
vdbelt committed Jul 19, 2019
1 parent 7d4e3b7 commit 446391b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Cors.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function handlePreflightRequest()
return $this->forbiddenResponse();
}

return $this->corsProfile->addPreflightHeaders(response('Preflight OK', 204));
return $this->corsProfile->addPreflightHeaders(response(null, 204));
}

protected function forbiddenResponse()
Expand Down
9 changes: 5 additions & 4 deletions tests/PreflightTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
class PreflightTest extends TestCase
{
/** @test */
public function it_responds_with_a_200_for_a_valid_preflight_request()
public function it_responds_with_a_204_for_a_valid_preflight_request()
{
$response = $this
->sendPreflightRequest('DELETE', 'https://spatie.be')
->assertSuccessful()
->assertSee('Preflight OK')
->assertStatus(204)
->assertHeader('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT, PATCH, DELETE')
->assertHeader('Access-Control-Allow-Headers', 'Content-Type, X-Auth-Token, Origin, Authorization')
->assertHeader('Access-Control-Allow-Origin', '*')
->assertHeader('Access-Control-Max-Age', 60 * 60 * 24);

$this->assertEmpty($response->content());
}

/** @test */
Expand Down Expand Up @@ -53,7 +54,7 @@ public function it_responds_with_correct_header_for_a_preflight_request_when_all
}

/** @test */
public function it_responds_with_a_200_for_a_preflight_request_coming_from_an_allowed_origin()
public function it_responds_with_a_204_for_a_preflight_request_coming_from_an_allowed_origin()
{
config()->set('cors.default_profile.allow_origins', ['https://spatie.be']);

Expand Down

0 comments on commit 446391b

Please sign in to comment.