Browse Source

update after PR 711

Maurits van der Schee 3 years ago
parent
commit
03d64bafed

+ 1
- 1
README.md View File

@@ -80,7 +80,7 @@ These are all the configuration options and their default value between brackets
80 80
 - "cacheType": `TempFile`, `Redis`, `Memcache`, `Memcached` or `NoCache` (`TempFile`)
81 81
 - "cachePath": Path/address of the cache (defaults to system's temp directory)
82 82
 - "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`)
84 84
 - "basePath": URI base path of the API (determined using PATH_INFO by default)
85 85
 
86 86
 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:

+ 8
- 2
src/Tqdev/PhpCrudApi/Middleware/CorsMiddleware.php View File

@@ -45,7 +45,10 @@ class CorsMiddleware extends Middleware
45 45
             $response = $this->responder->error(ErrorCode::ORIGIN_FORBIDDEN, $origin);
46 46
         } elseif ($method == 'OPTIONS') {
47 47
             $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
+            }
49 52
             if ($allowHeaders) {
50 53
                 $response = $response->withHeader('Access-Control-Allow-Headers', $allowHeaders);
51 54
             }
@@ -61,7 +64,10 @@ class CorsMiddleware extends Middleware
61 64
             if ($maxAge) {
62 65
                 $response = $response->withHeader('Access-Control-Max-Age', $maxAge);
63 66
             }
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
+            }
65 71
             if ($exposeHeaders) {
66 72
                 $response = $response->withHeader('Access-Control-Expose-Headers', $exposeHeaders);
67 73
             }

+ 1
- 2
tests/functional/001_records/041_cors_pre_flight.log View File

@@ -5,9 +5,8 @@ Access-Control-Request-Method: POST
5 5
 Access-Control-Request-Headers: X-XSRF-TOKEN, X-Requested-With
6 6
 ===
7 7
 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
9 9
 Access-Control-Allow-Methods: OPTIONS, GET, PUT, POST, DELETE, PATCH
10 10
 Access-Control-Max-Age: 1728000
11
-Access-Control-Expose-Headers: X-Debug-Info, X-Exception-Name, X-Exception-Message, X-Exception-File
12 11
 Access-Control-Allow-Credentials: true
13 12
 Access-Control-Allow-Origin: http://example.com

+ 1
- 2
tests/functional/002_auth/001_jwt_auth.log View File

@@ -38,8 +38,7 @@ Access-Control-Request-Method: POST
38 38
 Access-Control-Request-Headers: X-PINGOTHER, Content-Type
39 39
 ===
40 40
 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
42 42
 Access-Control-Allow-Methods: OPTIONS, GET, PUT, POST, DELETE, PATCH
43 43
 Access-Control-Allow-Credentials: true
44 44
 Access-Control-Max-Age: 1728000
45
-Access-Control-Expose-Headers: X-Debug-Info, X-Exception-Name, X-Exception-Message, X-Exception-File

Loading…
Cancel
Save