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

Explicitly request no-cache to discourage WP Cloud from edge caching CORS proxy results #1930

Merged
merged 3 commits into from
Oct 23, 2024
Merged
Changes from 1 commit
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
12 changes: 8 additions & 4 deletions packages/playground/php-cors-proxy/cors-proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
$httpcode_sent = false;
curl_setopt($ch, CURLOPT_HEADERFUNCTION, function($curl, $header) use($targetUrl, &$httpcode_sent, $ch) {
if(!$httpcode_sent) {
if (!$httpcode_sent) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just adding a space for consistency.

// Set the response code from the target server
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
http_response_code($httpCode);
Expand Down Expand Up @@ -129,7 +129,8 @@
header('Location: ' . $newLocation, true);
} else if (
stripos($header, 'Set-Cookie:') !== 0 &&
stripos($header, 'Authorization:') !== 0
stripos($header, 'Authorization:') !== 0 &&
stripos($header, 'Cache-Control:') !== 0
) {
header($header, false);
}
Expand Down Expand Up @@ -158,8 +159,11 @@
http_response_code(502);
echo "Bad Gateway – curl_exec error: " . curl_error($ch);
} else {
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
@http_response_code($httpCode);
if (!$httpcode_sent) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we may have already sent the HTTP response code and set $httpcode_sent, let's avoid setting the response code again.

$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
@http_response_code($httpCode);
}
@header('Cache-Control: no-cache');
}
// Close cURL session
curl_close($ch);
Loading