Skip to content

Commit

Permalink
实现exposed_headers参数
Browse files Browse the repository at this point in the history
  • Loading branch information
qeq66 authored and yunwuxin committed Apr 26, 2024
1 parent fcd5cf5 commit 822d90b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/HandleCors.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function __construct(Config $config)
$this->allowedOriginsPatterns = $options['allowed_origins_patterns'] ?? $this->allowedOriginsPatterns;
$this->allowedMethods = $options['allowed_methods'] ?? $this->allowedMethods;
$this->allowedHeaders = $options['allowed_headers'] ?? $this->allowedHeaders;
$this->exposedHeaders = $options['exposed_headers'] ?? $this->exposedHeaders;
$this->supportsCredentials = $options['supports_credentials'] ?? $this->supportsCredentials;

$maxAge = $this->maxAge;
Expand All @@ -45,9 +46,6 @@ public function __construct(Config $config)
}
$this->maxAge = $maxAge === null ? null : (int) $maxAge;

$exposedHeaders = $options['exposed_headers'] ?? $this->exposedHeaders;
$this->exposedHeaders = $exposedHeaders === false ? [] : $exposedHeaders;

// Normalize case
$this->allowedHeaders = array_map('strtolower', $this->allowedHeaders);
$this->allowedMethods = array_map('strtoupper', $this->allowedMethods);
Expand Down Expand Up @@ -96,6 +94,7 @@ protected function addPreflightRequestHeaders(Response $response, Request $reque
$this->configureAllowCredentials($response, $request);
$this->configureAllowedMethods($response, $request);
$this->configureAllowedHeaders($response, $request);
$this->configureExposedHeaders($response, $request);
$this->configureMaxAge($response, $request);
}

Expand Down Expand Up @@ -143,6 +142,14 @@ protected function configureAllowedHeaders(Response $response, Request $request)
$response->header(['Access-Control-Allow-Headers' => $allowHeaders]);
}

protected function configureExposedHeaders(Response $response, Request $request): void
{
if ($this->exposedHeaders) {
$exposeHeaders = implode(', ', $this->exposedHeaders);
$response->header(['Access-Control-Expose-Headers' => $exposeHeaders]);
}
}

protected function configureMaxAge(Response $response, Request $request): void
{
if ($this->maxAge !== null) {
Expand Down

0 comments on commit 822d90b

Please sign in to comment.