Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send X-Cors-Proxy-Allowed-Request-Headers header on proxied requests #238

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion inc/HttpClient/WPRemoteRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function __invoke( RequestInterface $request, array $options ): PromiseIn
try {
// Convert Guzzle request to arguments for wp_remote_request.
$url = (string) $request->getUri();
$headers = [];

// If we are running on WordPress Playground, use the provided CORS proxy.
if ( defined( 'USE_PLAYGROUND_CORS_PROXY' ) && true === USE_PLAYGROUND_CORS_PROXY ) {
Expand All @@ -40,11 +41,12 @@ public function __invoke( RequestInterface $request, array $options ): PromiseIn
->withQuery( $url );
$request = $request->withUri( $new_uri );
$url = (string) $new_uri;
$headers['X-Cors-Proxy-Allowed-Request-Headers'] = 'Authorization';
}

$args = [
'body' => (string) $request->getBody(), // Stream has been read, let __toString() rewind and read it.
'headers' => [],
'headers' => $headers,
'httpversion' => $options['httpversion'] ?? self::DEFAULT_HTTP_VERSION,
'method' => $request->getMethod(),
'timeout' => $options['timeout'] ?? self::DEFAULT_TIMEOUT,
Expand Down
Loading