Skip to content

Commit

Permalink
Added a Vary on Origin when responding to OPTIONS CORS-requests
Browse files Browse the repository at this point in the history
  • Loading branch information
fangel committed Jun 12, 2015
1 parent f2533de commit 327b1c1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions library/Imbo/EventListener/Cors.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ public function options(EventInterface $event) {
// This is an OPTIONS request, send 204 since no more content will follow
$response->setStatusCode(204);

// Vary on Origin to prevent caching allowed/disallowed requests
$event->getResponse()->setVary('Origin', false);

// Fall back if the passed origin is not allowed
if (!$this->originIsAllowed($origin)) {
return;
Expand Down
2 changes: 2 additions & 0 deletions tests/behat/features/cors-event-listener.feature
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Feature: Imbo provides an event listener for CORS
And the "Access-Control-Allow-Headers" response header contains "X-Imbo-Signature"
And the "Access-Control-Allow-Headers" response header contains "X-Imbo-Something"
And the "Access-Control-Max-Age" response header is "1349"
And the "Vary" response header contains "Origin"
And the "Allow" response header contains "GET"
And the "Allow" response header contains "HEAD"
And the "Allow" response header contains "OPTIONS"
Expand All @@ -55,6 +56,7 @@ Feature: Imbo provides an event listener for CORS
And Imbo uses the "cors.php" configuration
When I request "/" using HTTP "OPTIONS"
Then I should get a response with "204 No Content"
And the "Vary" response header contains "Origin"
And the "Allow" response header contains "GET"
And the "Allow" response header contains "HEAD"
And the "Allow" response header contains "OPTIONS"
Expand Down

0 comments on commit 327b1c1

Please sign in to comment.