-
Notifications
You must be signed in to change notification settings - Fork 210
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
Behavior mismatch: POST request with 302 response fails to redirect and doesn't set cookies #133
Comments
Looking through some code I think it would be possible to change the default behavior from
https://github.com/mrbbot/node-fetch/blob/bc466f48166cada665f9a068df933cc8a2a824d7/src/index.js#L81-L86 I didn't try this code above but it seems like it should work. |
It seems that |
@vzaramel and I worked in a fix for this and we created a commit to fix it: clickfunnels2@4c3d294. There is a test failing related to subrequests counting which I didn't go deep to investigate, but it's not affecting the purposes of the way we are using Miniflare still:
Maybe this change could be considered to be added in current v2 branch. |
Hey everyone! 👋 First off, thank you very much for the detailed repoduction @hansede 🧡. Spent a little time tonight looking into this. When I tried proxying through Miniflare, I got a import { fetch } from "undici";
await fetch("http://localhost:3000/", { method: "GET", headers: { "Content-Length": "0" }}); Removing the Thanks also @vzaramel and @hnrqer 🧡 for identifying and working on a potential fix for the redirect issue. I've got a few comments/questions:
Apologies I've only just gotten round to this. |
Not entirely completely sure about about this one and the implications on all GET requests. For our tests, normal GET requests weren't impacted when using
Yes, if we don't wanna expose the internal response we could simply get the internalResponse in the http-server package or somewhere else.
This is what undici does for manual redirects (it actually sets the body to null),
we've just set the body to
I think we had an issue in that part because the body was a structure returned by undici where the stream lives in
Hmm, do you mean that should live in the It's also interesting to see the discussion around the issues in that PR.
NP, really. Thanks for replying this issue, the Miniflare project is really helping us, so actually thank you for all the contributions in this project. |
I think @mrbbot meant to implement it arround here. miniflare/packages/core/src/standards/http.ts Lines 637 to 650 in a57b936
The best case would be to undici to patch their code as deno did as @hnrqer pointed out. But meanwhile we could have this fix in here ^^ |
Also sets the `redirect` mode of incoming requests to `manual`: https://developers.cloudflare.com/workers/runtime-apis/request#requestinit This ensures redirects are proxied to the end user, meaning cookies set in responses are stored in the browser. Co-Authored-By: Henrique Sarmento <hnrqer@gmail.com> Co-Authored-By: Vinicius Zaramella <vinicius.zaramella@gmail.com>
Awesome 👍, thanks for all your responses. That Deno PR was very interesting. I noticed Cloudflare actually sets the |
Also sets the `redirect` mode of incoming requests to `manual`: https://developers.cloudflare.com/workers/runtime-apis/request#requestinit This ensures redirects are proxied to the end user, meaning cookies set in responses are stored in the browser. Co-Authored-By: Henrique Sarmento <hnrqer@gmail.com> Co-Authored-By: Vinicius Zaramella <vinicius.zaramella@gmail.com>
Hey! 👋 Miniflare |
Expected (Cloudflare behavior)
When making a POST request on an endpoint to which the origin server responds with a 302 status code, I expect that my client will receive the 302 status code, proxied through Miniflare, and be redirected accordingly. I also expect the
set-cookie
header on the 302 response sent from the origin server to be present when the response is received by the client.Actual (Miniflare behavior)
When making a POST request to an endpoint that responds with a 302 status code, Miniflare internally resolves the 302 and returns a 200 status code instead. My client is not redirected to a new URL, and instead the contents of the page I would have been redirected to are served up at the original URL (where I made the POST request). The
set-cookie
response header from the 302 response is absent on the 200 response.Example
Express server (server.js):
Miniflare worker (worker.js):
To run the Express server:
To run the Miniflare server:
miniflare worker.js -u http://localhost:3000
Hitting the Express server directly:
/redirect/
/
sessionid
cookie will now be setHitting the Express server, proxied through Miniflare:
/redirect/
/
, but the URL will still be/redirect/
sessionid
cookie will not be setI would expect the behavior to be the same whether proxied through Miniflare or not.
The text was updated successfully, but these errors were encountered: