Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit cd76f58

Browse files
senadiropr
authored andcommitted
Don't send headers early in Store API (#10241)
1 parent 5efdd2e commit cd76f58

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/StoreApi/Authentication.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,15 @@ public function send_cors_headers( $value, $result, $request ) {
6161
}
6262

6363
// Send standard CORS headers.
64-
header( 'Access-Control-Allow-Methods: OPTIONS, GET, POST, PUT, PATCH, DELETE' );
65-
header( 'Access-Control-Allow-Credentials: true' );
66-
header( 'Vary: Origin', false );
64+
$server = rest_get_server();
65+
$server->send_header( 'Access-Control-Allow-Methods', 'OPTIONS, GET, POST, PUT, PATCH, DELETE' );
66+
$server->send_header( 'Access-Control-Allow-Credentials', 'true' );
67+
$server->send_header( 'Vary', 'Origin', false );
6768

6869
// Allow preflight requests, certain http origins, and any origin if a cart token is present. Preflight requests
6970
// are allowed because we'll be unable to validate cart token headers at that point.
7071
if ( $this->is_preflight() || $this->has_valid_cart_token( $request ) || is_allowed_http_origin( $origin ) ) {
71-
header( 'Access-Control-Allow-Origin: ' . $origin );
72+
$server->send_header( 'Access-Control-Allow-Origin', $origin );
7273
}
7374

7475
// Exit early during preflight requests. This is so someone cannot access API data by sending an OPTIONS request

0 commit comments

Comments
 (0)