denoland / fresh

The next-gen web framework.
https://fresh.deno.dev
MIT License
12.59k stars 650 forks source link

Bug: POST redirects with basepath wrong method. #2632

Open marvinhagemeister opened 2 months ago

marvinhagemeister commented 2 months ago

From discord https://discord.com/channels/684898665143206084/991511118524715139/1279100135606849619

When using deno fresh alone with the basepath config parameter set (let's say "/basepath"), all requests made to "/" are redirect to "/basepath" with a 302 Found status (this is correct I think). But when the request is a POST, the redirection is made with a GET, I think the init method is not reused.

jake-abed commented 2 months ago

Confirming that this bug still exists as of 1.7.1

Can be quickly verified by adding handlers.

Checking MDN's resources on temporary redirections, the source of the issue may be choosing to use a 302 instead of a 307:

302 - Found - GET methods unchanged. Others may or may not be changed to GET. [2]

307 - Temporary Redirect - Method and body not changed

I think the fix for this could be so simple as swapping the status code in Context. If this still isn't resolved this evening, I'd love to give it a shot and open up a PR.

Edit: Or is this even worth fixing? I think it may be fixed by Fresh 2.0 but need to sleuth more.