Skip to content

Commit

Permalink
Merge branch 'nusphere-develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jk committed Mar 4, 2024
2 parents b117518 + 83c20f1 commit d8d67dc
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/JK/RestServer/HeaderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ final class HeaderManager
/** @var array Colletion of HTTP headers */
private $headers = array();

/** These headers are only once allowed */
private $singleHeader = [
"Access-Control-Allow-Origin"
];

/**
* Sets some defaults
*/
Expand Down Expand Up @@ -121,7 +126,23 @@ public function sendAllHeaders()
}

foreach ($this->headers as $name => $value) {
header($name . ': ' . $value);
if (!$this->isSingleHeaderAndNotAlreadySent($name)) {
header($name . ': ' . $value);
}
}
}

/**
* Bugfix: Remove duplicates of headers which are required to be single
*
* https://stackoverflow.com/questions/15682496/will-duplicate-access-control-allow-origin-headers-break-cors
*/
private function isSingleHeaderAndNotAlreadySent(string $name): bool
{
if (!in_array($name, $this->singleHeader)) {
return false;
}

return array_key_exists($name, array_keys(headers_list()));
}
}

0 comments on commit d8d67dc

Please sign in to comment.