Skip to content

Commit 7299696

Browse files
committed
fix append vary header
1 parent 63e4037 commit 7299696

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

system/Filters/Cors.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,24 @@ public function before(RequestInterface $request, $arguments = null)
6161
/** @var ResponseInterface $response */
6262
$response = service('response');
6363

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

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

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

0 commit comments

Comments
 (0)