Skip to content

Commit d9f9418

Browse files
committed
BUGFIX: The CORS middleware will create the response for an OPTIONS request without passing the request down through the process chain
Without this change the preflight lead to a 404 as the OPTIONS request could not be routed which yielded a 404 exception.
1 parent 8ca6c1b commit d9f9418

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Classes/Http/CorsHeaderMiddleware.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Lmc\HttpConstants\Header;
88
use Neos\Flow\Annotations as Flow;
9+
use Psr\Http\Message\ResponseFactoryInterface;
910
use Psr\Http\Message\ResponseInterface;
1011
use Psr\Http\Message\ServerRequestInterface;
1112
use Psr\Http\Server\MiddlewareInterface;
@@ -14,6 +15,12 @@
1415

1516
class CorsHeaderMiddleware implements MiddlewareInterface
1617
{
18+
/**
19+
* @Flow\Inject
20+
* @var ResponseFactoryInterface
21+
*/
22+
protected $responseFactory;
23+
1724
/**
1825
* @Flow\InjectConfiguration("enabled")
1926
*/
@@ -73,15 +80,16 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
7380
}
7481

7582
$this->initializeConfiguration();
76-
77-
$response = $handler->handle($request);
7883
$method = $request->getMethod();
7984

8085
// method type is not options, return early
8186
if ($method == 'OPTIONS') {
8287
$this->logger->debug('CORS Component: Preflight request');
88+
$response = $this->responseFactory->createResponse();
8389
return $this->handlePreflight($request, $response);
8490
}
91+
92+
$response = $handler->handle($request);
8593
return $this->handleRequest($request, $response);
8694
}
8795

0 commit comments

Comments
 (0)