Skip to content

Commit c060399

Browse files
committed
Improve CORS header implementation
1 parent 3fadb01 commit c060399

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

api.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2588,20 +2588,20 @@ protected function swagger($settings) {
25882588
}
25892589

25902590
protected function allowOrigin($origin,$allowOrigins) {
2591-
if ($origin) foreach (explode(',',$allowOrigins) as $o) {
2592-
if (preg_match('/^'.str_replace('\*','.*',preg_quote(strtolower(trim($o)))).'$/',$origin)) {
2593-
header('Access-Control-Allow-Origin: '.$origin);
2594-
break;
2591+
if (isset($_SERVER['REQUEST_METHOD'])) {
2592+
header('Access-Control-Allow-Credentials: true');
2593+
foreach (explode(',',$allowOrigins) as $o) {
2594+
if (preg_match('/^'.str_replace('\*','.*',preg_quote(strtolower(trim($o)))).'$/',$origin)) {
2595+
header('Access-Control-Allow-Origin: '.$origin);
2596+
break;
2597+
}
25952598
}
2596-
} else {
2597-
header('Access-Control-Allow-Origin: *');
25982599
}
25992600
}
26002601

26012602
public function executeCommand() {
2602-
if (isset($_SERVER['REQUEST_METHOD'])) {
2603+
if ($this->settings['origin']) {
26032604
$this->allowOrigin($this->settings['origin'],$this->settings['allow_origin']);
2604-
header('Access-Control-Allow-Credentials: true');
26052605
}
26062606
if (!$this->settings['request']) {
26072607
$this->swagger($this->settings);

0 commit comments

Comments
 (0)