@@ -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