- Notifications
You must be signed in to change notification settings - Fork 349
[Cors Proxy] Support Transfer-Encoding: Chunked #2077
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Adjusts the CORS Proxy to relay chunked responses using chunks. ## Implementation Some APIs use fixed content-length and respond with a predictable response body. Other APIs respond with chunks. Before this PR, whenever the CORS proxy received a chunked response, it would only relay the `Transfer-Encoding: Chunked` header without actually transmitting the response body as chunks. Chunks are an essential HTTP 1.1 feature that cannot be disabled, We also can't just filter out that header in the proxy response as the client expects either a Content-Length or body chunks, and we may not know the Content-length upfront. With this PR, the CORS proxy outputs its response using the chunked encoding whenever the remote endpoint streams its response using the chunked encoding. ## Testing * Run `nx start playground-php-cors-proxy` * Fixed-length response: Go to http://127.0.0.1:5263/cors-proxy.php?https://raw.githubusercontent.com/WordPress/wordpress-playground/5e5ba3e0f5b984ceadd5cbe6e661828c14621d25/README.md * Confirm it loaded the file * Chunked encoding: Go to http://127.0.0.1:5263/cors-proxy.php?https://api.wordpress.org/plugins/update-check/1.1/ * Confirm the response says the word `error` * Error handling: Go to http://127.0.0.1:5263/cors-proxy.php?https://nosuchsite.playground.wordpress.net * Confirm the response says Bad Request Hostname could not be resolved
adamziel commented Dec 12, 2024
header('Access-Control-Allow-Credentials: true'); | ||
header('Access-Control-Allow-Methods: GET, POST, OPTIONS'); | ||
header('Access-Control-Allow-Headers: Accept, Authorization, Content-Type, git-protocol'); | ||
header('Access-Control-Allow-Headers: Accept, Authorization, Content-Type, git-protocol, wp_blog, wp_install'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Casual addition – these two headers are used by WordPress core when requesting api.w.org
edisplay pushed a commit to edisplay/wordpress-playground that referenced this pull request Dec 17, 2024
…he latest release (WordPress#2056) Fixes a regression created in WordPress#2077. The minified nightly build accidentally became a minified build of the latest WordPress version. In the multitude of resolveWordPressRelease() calls used in building the minified WordPress releases, the last call in the chain started transforming the nightly URL into a 6.7.1 release URL. This PR removes that one final call, and also simplifies the Playground CLI build pipeline. ## Testing instructions Apply this PR, switch WP version to nightly, confirm in wp-=admin it's indeed the nightly release
adamziel added a commit that referenced this pull request Jan 2, 2025
Adds support for `transfer-encoding: chunked` on Apache, Nginx, and other web servers. #2077 added support for `transfer-encoding: chunked` in a way that works on a local PHP dev server. The proxy manually chunks the output bytes and outputs each chunk's header, separator, body, and trailer. However, it doesn't work on playground.wordpress.net because the web server there handles the chunked encoding on its own. The bytes echoed by cors-proxy.php are treated as body bytes, which messes up the response body. This PR restricts the manual chunking to a local CLI dev server. ## Testing instructions Run cors-proxy.php in Apache or so and confirm that requesting resources served with chunked encoding works with this patch but not without it. One such URL is https://adamadam.blog/feed/.
adamziel added a commit that referenced this pull request Jan 9, 2025
#2114) Adds support for `transfer-encoding: chunked` on Apache, Nginx, and other web servers. #2077 added support for `transfer-encoding: chunked` in a way that works on a local PHP dev server. The proxy manually chunks the output bytes and outputs each chunk's header, separator, body, and trailer. However, it doesn't work on playground.wordpress.net because the web server there handles the chunked encoding on its own. The bytes echoed by cors-proxy.php are treated as body bytes, which messes up the response body. This PR restricts the manual chunking to a local CLI dev server. ## Testing instructions Run cors-proxy.php in Apache or so and confirm that requesting resources served with chunked encoding works with this patch but not without it. One such URL is https://adamadam.blog/feed/.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Adjusts the CORS Proxy to relay chunked responses using chunks.
Implementation
Some APIs use fixed content-length and respond with a predictable response body. Other APIs respond with chunks.
Before this PR, whenever the CORS proxy received a chunked response, it would only relay the
Transfer-Encoding: Chunked
header without actually transmitting the response body as chunks.Chunks are an essential HTTP 1.1 feature that cannot be disabled, We also can't just filter out that header in the proxy response as the client expects either a Content-Length or body chunks, and we may not know the Content-length upfront.
With this PR, the CORS proxy outputs its response using the chunked encoding whenever the remote endpoint streams its response using the chunked encoding.
Testing
nx start playground-php-cors-proxy
error