Skip to content

Commit 178ae03

Browse files
committed
Tweak defaults
1 parent 46d32c9 commit 178ae03

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ This package can be used as a library. You can use it in your framework using:
3333
| allowedOrigins | Matches the request origin. | `[]` |
3434
| allowedOriginsPatterns | Matches the request origin with `preg_match`. | `[]` |
3535
| allowedHeaders | Sets the Access-Control-Allow-Headers response header. | `[]` |
36-
| exposedHeaders | Sets the Access-Control-Expose-Headers response header. | `false` |
37-
| maxAge | Sets the Access-Control-Max-Age response header. | `false` |
36+
| exposedHeaders | Sets the Access-Control-Expose-Headers response header. | `[]` |
37+
| maxAge | Sets the Access-Control-Max-Age response header. | `0` |
3838
| supportsCredentials | Sets the Access-Control-Allow-Credentials header. | `false` |
3939

4040
The _allowedMethods_ and _allowedHeaders_ options are case-insensitive.

src/CorsService.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,18 @@ private function normalizeOptions(array $options = []): array
5555
'maxAge' => 0,
5656
];
5757

58-
if ($options['exposedHeaders'] && !is_array($options['exposedHeaders'])) {
59-
throw new InvalidOptionException("CORS option `exposedHeaders` should be `false` or an array");
58+
if ($options['exposedHeaders'] === false) {
59+
$options['exposedHeaders'] = [];
6060
}
6161

62-
foreach (['allowedOrigins', 'allowedOriginsPatterns', 'allowedHeaders', 'allowedMethods'] as $key) {
62+
$arrayHeaders = [
63+
'allowedOrigins',
64+
'allowedOriginsPatterns',
65+
'allowedHeaders',
66+
'allowedMethods',
67+
'exposedHeaders',
68+
];
69+
foreach ($arrayHeaders as $key) {
6370
if (!is_array($options[$key])) {
6471
throw new InvalidOptionException("CORS option `{$key}` should be an array");
6572
}

0 commit comments

Comments
 (0)