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

Conversation

brandonpayton
Copy link
Member

Motivation for the change, related issues

This PR attempts to disable WP Cloud edge caching of CORS proxy responses.

Closes #1920

Implementation details

This PR updates the CORS proxy to always include a Cache-Control: no-cache header with normal proxy responses.

Testing Instructions (or ideally a Blueprint)

  • Add a temporary cors-proxy-config.php that defines a truthy PLAYGROUND_CORS_PROXY_DISABLE_RATE_LIMIT constant. This disables rate-limiting checks which are irrelevant to this change.
  • Run local PHP web server using php -S localhost:7777
  • Test that CORS proxy continues to work
  • In a browser, test that http://localhost:7777/cors-proxy.php?https://wordpress.org responds with a Cache-Control: no-cache header

@brandonpayton brandonpayton self-assigned this Oct 23, 2024
@brandonpayton brandonpayton added [Type] Bug An existing feature does not function as intended [Package][@wp-playground] CORS Proxy labels Oct 23, 2024
@brandonpayton brandonpayton requested a review from a team October 23, 2024 04:34
@brandonpayton brandonpayton changed the title Explicitly request no-cache to avoid WP Cloud edge caching CORS proxy results Explicitly request no-cache to discourage WP Cloud from edge caching CORS proxy results Oct 23, 2024
@@ -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.

@@ -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.

@brandonpayton brandonpayton merged commit 5e5ba3e into trunk Oct 23, 2024
8 of 9 checks passed
@brandonpayton brandonpayton deleted the disable-wp-cloud-edge-caching branch October 23, 2024 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package][@wp-playground] CORS Proxy [Type] Bug An existing feature does not function as intended
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Avoid WP Cloud edge caching for CORS proxy
1 participant