Skip to content

Commit bde5916

Browse files
authored
Only add CORS headers when origin header is added (#76)
1 parent 03157d5 commit bde5916

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/CorsService.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,16 @@ public function handlePreflightRequest(Request $request)
8484
public function addPreflightRequestHeaders(Response $response, Request $request)
8585
{
8686
$this->configureAllowedOrigin($response, $request);
87+
88+
if ($response->headers->has('Access-Control-Allow-Origin')) {
89+
$this->configureAllowCredentials($response, $request);
8790

88-
$this->configureAllowCredentials($response, $request);
91+
$this->configureAllowedMethods($response, $request);
8992

90-
$this->configureAllowedMethods($response, $request);
93+
$this->configureAllowedHeaders($response, $request);
9194

92-
$this->configureAllowedHeaders($response, $request);
93-
94-
$this->configureMaxAge($response, $request);
95+
$this->configureMaxAge($response, $request);
96+
}
9597

9698
return $response;
9799
}
@@ -125,9 +127,11 @@ public function addActualRequestHeaders(Response $response, Request $request)
125127
{
126128
$this->configureAllowedOrigin($response, $request);
127129

128-
$this->configureAllowCredentials($response, $request);
130+
if ($response->headers->has('Access-Control-Allow-Origin')) {
131+
$this->configureAllowCredentials($response, $request);
129132

130-
$this->configureExposedHeaders($response, $request);
133+
$this->configureExposedHeaders($response, $request);
134+
}
131135

132136
return $response;
133137
}

0 commit comments

Comments
 (0)