Skip to content

Commit 36f12eb

Browse files
cicnavipradtke
authored andcommitted
Add Access-Control-Allow-Origin header, if not already present.
1 parent 0948322 commit 36f12eb

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/Services/RoutingService.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,23 @@ private static function callController($container, string $controllerClassname):
8181
$response->data['messages'] = $container->get(SessionMessagesService::class)->getMessages();
8282
}
8383

84+
// If not already handled, allow CORS (for JS clients).
85+
if (!$response->headers->has('Access-Control-Allow-Origin')) {
86+
$response->headers->set('Access-Control-Allow-Origin', '*');
87+
}
88+
89+
8490
$response->send();
8591

8692
return;
8793
}
8894

8995
if ($response instanceof ResponseInterface) {
96+
// If not already handled, allow CORS (for JS clients).
97+
if (!$response->hasHeader('Access-Control-Allow-Origin')) {
98+
$response = $response->withHeader('Access-Control-Allow-Origin', '*');
99+
}
100+
90101
$emitter = new SapiEmitter();
91102

92103
$emitter->emit($response);

0 commit comments

Comments
 (0)