Skip to content

Commit

Permalink
Skip wildcard conversion when all origin is allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
barryvdh committed Feb 19, 2022
1 parent eff8fdb commit 07611b4
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/CorsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,6 @@ private function validateOptions(): void

private function normalizeOptions(): void
{
// Transform wildcard pattern
foreach ($this->allowedOrigins as $origin) {
if (strpos($origin, '*') !== false) {
$this->allowedOriginsPatterns[] = $this->convertWildcardToPattern($origin);
}
}

// Normalize case
$this->allowedHeaders = array_map('strtolower', $this->allowedHeaders);
$this->allowedMethods = array_map('strtoupper', $this->allowedMethods);
Expand All @@ -120,6 +113,15 @@ private function normalizeOptions(): void
$this->allowAllOrigins = in_array('*', $this->allowedOrigins);
$this->allowAllHeaders = in_array('*', $this->allowedHeaders);
$this->allowAllMethods = in_array('*', $this->allowedMethods);

// Transform wildcard pattern
if (!$this->allowAllOrigins) {
foreach ($this->allowedOrigins as $origin) {
if (strpos($origin, '*') !== false) {
$this->allowedOriginsPatterns[] = $this->convertWildcardToPattern($origin);
}
}
}
}

/**
Expand Down

0 comments on commit 07611b4

Please sign in to comment.