[miniflare] fix: ensure redirects handled correctly with dispatchFetch()
#5191
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.
What this PR solves / how to test
Fixes #5018.
Previously, if your Worker returned a redirect response, calling
dispatchFetch(url)
would send another request to the originalurl
rather than the redirect. This happened because...this.#runtimeDispatcher
forfetch()
ing, which only sends request to the runtime. This meant if a Worker returned a redirect to a different origin, that origin would be ignored and the request would still go to the runtime.MF-Original-URL
header was not cleared/modified during redirects. This meant if a Worker returned a relative/absolute redirect to the same runtime origin, the path would not be updated in therequest
received by the user.This change ensures redirects are followed correctly.
url
, the request will be sent to the Worker.url
, the request will also be sent to the Worker.Tests have been added to cover the different types of redirect. 👍
Author has addressed the following