feat(fetch): support following redirect responses#627
Merged
kettanaito merged 3 commits intomainfrom Sep 8, 2024
Merged
Conversation
8955263 to
e9ef8c7
Compare
e9ef8c7 to
9fba26d
Compare
This was referenced Sep 7, 2024
Closed
kettanaito
commented
Sep 7, 2024
| await httpServer.close() | ||
| }) | ||
|
|
||
| it('follows a bypassed redirect response', async () => { |
Member
Author
There was a problem hiding this comment.
Added the tests for all scenarios we can reproduce from Undici.
kettanaito
commented
Sep 7, 2024
| /** | ||
| * @see https://github.com/nodejs/undici/blob/a6dac3149c505b58d2e6d068b97f4dc993da55f0/lib/web/fetch/index.js#L1210 | ||
| */ | ||
| export async function followFetchRedirect( |
Member
Author
There was a problem hiding this comment.
Implementation of following redirects.
kettanaito
commented
Sep 7, 2024
| * This way, the client can manually follow the redirect it receives. | ||
| * @see https://github.com/nodejs/undici/blob/a6dac3149c505b58d2e6d068b97f4dc993da55f0/lib/web/fetch/index.js#L1173 | ||
| */ | ||
| if (RESPONSE_STATUS_CODES_WITH_REDIRECT.has(response.status)) { |
Member
Author
There was a problem hiding this comment.
Fix: handle redirect responses in a special way.
Member
Author
|
I'd also look into following redirects in |
Member
Author
Released: v0.35.0 🎉This has been released in v0.35.0! Make sure to always update to the latest version ( Predictable release automation by @ossjs/release. |
Member
|
Amazing PR! |
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.
Warning
Marking this as a breaking (feat) release because mocked redirect responses will now be followed by default (previously, returned as-is). The previous behavior was faulty and not spec-compliant, but I don't want to break consumers once again.
The redirect response handling is taken from Undici almost as-is because it doesn't export its
web/fetch/utilsas a typed module (it's untyped CJS). Luckily, Undici follows the spec in those implementations so they are unlikely to change. I'm also omitting things that are exclusive to Undici, such as accessingrequest.body.source.Relevant resources