@@ -61,16 +61,24 @@ public function before(RequestInterface $request, $arguments = null)
61
61
/** @var ResponseInterface $response */
62
62
$ response = service ('response ' );
63
63
64
- if ($ request ->is ('OPTIONS ' )) {
64
+ if ($ this ->cors ->isPreflightRequest ($ request )) {
65
+ $ response = $ this ->cors ->handlePreflightRequest ($ request , $ response );
66
+
65
67
// Always adds `Vary: Access-Control-Request-Method` header for cacheability.
66
68
// If there is an intermediate cache server such as a CDN, if a plain
67
69
// OPTIONS request is sent, it may be cached. But valid preflight requests
68
70
// have this header, so it will be cached separately.
69
71
$ response ->appendHeader ('Vary ' , 'Access-Control-Request-Method ' );
72
+
73
+ return $ response ;
70
74
}
71
75
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 ' );
74
82
}
75
83
76
84
$ this ->cors ->addResponseHeaders ($ request , $ response );
0 commit comments