Skip to content

Commit 03d64ba

Browse files
committed
update after PR 711
1 parent 317839e commit 03d64ba

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ These are all the configuration options and their default value between brackets
8080
- "cacheType": `TempFile`, `Redis`, `Memcache`, `Memcached` or `NoCache` (`TempFile`)
8181
- "cachePath": Path/address of the cache (defaults to system's temp directory)
8282
- "cacheTime": Number of seconds the cache is valid (`10`)
83-
- "debug": Show errors in the "X-Debug-Info" header (`false`)
83+
- "debug": Show errors in the "X-Exception" headers (`false`)
8484
- "basePath": URI base path of the API (determined using PATH_INFO by default)
8585

8686
All configuration options are also available as environment variables. Write the config option with capitals, a "PHP_CRUD_API_" prefix and underscores for word breakes, so for instance:

src/Tqdev/PhpCrudApi/Middleware/CorsMiddleware.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
4545
$response = $this->responder->error(ErrorCode::ORIGIN_FORBIDDEN, $origin);
4646
} elseif ($method == 'OPTIONS') {
4747
$response = ResponseFactory::fromStatus(ResponseFactory::OK);
48-
$allowHeaders = $this->getProperty('allowHeaders', 'Content-Type, X-XSRF-TOKEN, X-Authorization, X-Debug-Info, X-Exception-Name, X-Exception-Message, X-Exception-File');
48+
$allowHeaders = $this->getProperty('allowHeaders', 'Content-Type, X-XSRF-TOKEN, X-Authorization');
49+
if ($this->debug) {
50+
$allowHeaders = implode(', ', array_filter([$allowHeaders, 'X-Exception-Name, X-Exception-Message, X-Exception-File']));
51+
}
4952
if ($allowHeaders) {
5053
$response = $response->withHeader('Access-Control-Allow-Headers', $allowHeaders);
5154
}
@@ -61,7 +64,10 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
6164
if ($maxAge) {
6265
$response = $response->withHeader('Access-Control-Max-Age', $maxAge);
6366
}
64-
$exposeHeaders = $this->getProperty('exposeHeaders', 'X-Debug-Info, X-Exception-Name, X-Exception-Message, X-Exception-File');
67+
$exposeHeaders = $this->getProperty('exposeHeaders', '');
68+
if ($this->debug) {
69+
$exposeHeaders = implode(', ', array_filter([$exposeHeaders, 'X-Exception-Name, X-Exception-Message, X-Exception-File']));
70+
}
6571
if ($exposeHeaders) {
6672
$response = $response->withHeader('Access-Control-Expose-Headers', $exposeHeaders);
6773
}

tests/functional/001_records/041_cors_pre_flight.log

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ Access-Control-Request-Method: POST
55
Access-Control-Request-Headers: X-XSRF-TOKEN, X-Requested-With
66
===
77
200
8-
Access-Control-Allow-Headers: Content-Type, X-XSRF-TOKEN, X-Authorization, X-Debug-Info, X-Exception-Name, X-Exception-Message, X-Exception-File
8+
Access-Control-Allow-Headers: Content-Type, X-XSRF-TOKEN, X-Authorization
99
Access-Control-Allow-Methods: OPTIONS, GET, PUT, POST, DELETE, PATCH
1010
Access-Control-Max-Age: 1728000
11-
Access-Control-Expose-Headers: X-Debug-Info, X-Exception-Name, X-Exception-Message, X-Exception-File
1211
Access-Control-Allow-Credentials: true
1312
Access-Control-Allow-Origin: http://example.com

tests/functional/002_auth/001_jwt_auth.log

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ Access-Control-Request-Method: POST
3838
Access-Control-Request-Headers: X-PINGOTHER, Content-Type
3939
===
4040
200
41-
Access-Control-Allow-Headers: Content-Type, X-XSRF-TOKEN, X-Authorization, X-Debug-Info, X-Exception-Name, X-Exception-Message, X-Exception-File
41+
Access-Control-Allow-Headers: Content-Type, X-XSRF-TOKEN, X-Authorization
4242
Access-Control-Allow-Methods: OPTIONS, GET, PUT, POST, DELETE, PATCH
4343
Access-Control-Allow-Credentials: true
4444
Access-Control-Max-Age: 1728000
45-
Access-Control-Expose-Headers: X-Debug-Info, X-Exception-Name, X-Exception-Message, X-Exception-File

0 commit comments

Comments
 (0)