feat: implement redirect property for fetch#734
Merged
saghul merged 2 commits intosaghul:masterfrom Jan 8, 2026
Merged
Conversation
Owner
|
Code looks good! Can you run make js and commit the results? |
Contributor
Author
|
|
Owner
|
Hum, I'll take a look. |
Contributor
Author
|
If I change the URL in Since the content-length header isn't mandatory, the progress callback will probably not work properly for some sites. |
Owner
|
Sure, sounds good, thanks for chasing it down! |
saghul
reviewed
Jan 8, 2026
This implements the `redirect` functionality for the fetch API. Since fetch is implemented in terms of `XMLHttpRequest`, a non-standard `redirectMode` property had to be added. Internally it is implemented using the `CURLOPT_FOLLOWLOCATION` and `CURLOPT_MAXREDIRS` options.
The XHR progress test now fails when using `postman-echo.com/get`. This seems to be because `postman-echo` is no longer sending the Content-Length response header (which is not mandatory). As an intermediate "solution", to get the test to pass, we switch to a url that still does send the Content-Length header.
saghul
approved these changes
Jan 8, 2026
Owner
|
Cheers! |
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
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.
This implements the
redirectfunctionality for the Fetch API.More info on the redirect property can be found here.
Since fetch is implemented in terms of
XMLHttpRequest, this poses some issues.Standard
XMLHttpRequestalways follows redirects and does not provide an API to change the behaviour.Therefore, I had to add a non-standard
redirectModeproperty.I do believe this is justified, since the Fetch API is promoted as a replacement for
XMLHttpRequest(e.g. here).So having a more feature-complete implementation for Fetch should take priority, in my opinion.
Internally it is implemented by:
CURLOPT_FOLLOWLOCATIONto 0 in case of'manual'redirectsCURLOPT_MAXREDIRSto 0 in case of'error'redirects.What do you think?