Skip to content

fix: change redirect default status from 302 to 307#3671

Closed
ddmoney420 wants to merge 1 commit intodenoland:mainfrom
ddmoney420:fix/redirect-307-for-post
Closed

fix: change redirect default status from 302 to 307#3671
ddmoney420 wants to merge 1 commit intodenoland:mainfrom
ddmoney420:fix/redirect-307-for-post

Conversation

@ddmoney420
Copy link

Summary

Changes the default redirect status code from 302 to 307 to preserve the original HTTP method on redirect.

This fixes POST redirects being converted to GET requests when using basepath configuration.

Problem

Per RFC 7231:

  • 302 Found: User agents MAY change the request method (browsers convert POST→GET)
  • 307 Temporary Redirect: Method and body MUST NOT be changed

The current default of 302 breaks form submissions when redirecting, as POST requests become GET requests.

Solution

Change the default status in ctx.redirect() from 302 to 307.

Users who explicitly need 302 behavior can still pass it:

ctx.redirect("/path", 302)

Test plan

  • Updated existing redirect tests to expect 307 as default
  • Added test verifying explicit 302 still works for backward compatibility

Fixes #2632

🤖 Generated with Claude Code

Changes the default redirect status code from 302 to 307 to preserve
the original HTTP method on redirect. This fixes POST redirects being
converted to GET requests when using basepath.

Per RFC 7231:
- 302 Found: User agents MAY change POST to GET (browsers do this)
- 307 Temporary Redirect: Method MUST NOT be changed

Users who explicitly need 302 behavior can still pass it:
`ctx.redirect("/path", 302)`

Fixes denoland#2632

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@ddmoney420
Copy link
Author

Closing this PR as part of cleaning up my contributions. I spread too thin across projects. Apologies for the noise.

@ddmoney420 ddmoney420 closed this Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: POST redirects with basepath wrong method.

1 participant