Skip to content

Commit

Permalink
fix append vary header
Browse files Browse the repository at this point in the history
  • Loading branch information
michalsn committed Jan 27, 2025
1 parent 63e4037 commit 7299696
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions system/Filters/Cors.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,24 @@ public function before(RequestInterface $request, $arguments = null)
/** @var ResponseInterface $response */
$response = service('response');

if ($request->is('OPTIONS')) {
if ($this->cors->isPreflightRequest($request)) {
$response = $this->cors->handlePreflightRequest($request, $response);

// Always adds `Vary: Access-Control-Request-Method` header for cacheability.
// If there is an intermediate cache server such as a CDN, if a plain
// OPTIONS request is sent, it may be cached. But valid preflight requests
// have this header, so it will be cached separately.
$response->appendHeader('Vary', 'Access-Control-Request-Method');

return $response;
}

if ($this->cors->isPreflightRequest($request)) {
return $this->cors->handlePreflightRequest($request, $response);
if ($request->is('OPTIONS')) {
// Always adds `Vary: Access-Control-Request-Method` header for cacheability.
// If there is an intermediate cache server such as a CDN, if a plain
// OPTIONS request is sent, it may be cached. But valid preflight requests
// have this header, so it will be cached separately.
$response->appendHeader('Vary', 'Access-Control-Request-Method');
}

$this->cors->addResponseHeaders($request, $response);
Expand Down

0 comments on commit 7299696

Please sign in to comment.