8000 docs: document redirect status code method-change semantics per RFC 7231 by kawasima · Pull Request #83 · enkan/enkan · GitHub
[go: up one dir, main page]

Skip to content

docs: document redirect status code method-change semantics per RFC 7231 - #83

Merged
kawasima merged 3 commits into
developfrom
fix/rfc7231-redirect-status-javadoc
Mar 8, 2026
Merged

kawasima merged 3 commits into
developfrom
fix/rfc7231-redirect-status-javadoc

Conversation

@kawasima
@kawasima kawasima commented Mar 8, 2026
Copy link
Copy Markdown
Collaborator

Summary

  • Adds Javadoc to all five RedirectStatusCode enum constants clarifying which codes are method-changing (301, 302, 303) and which are method-preserving (307, 308), with RFC 7231 §6.4 and RFC 7538 §3 references
  • Adds an enum-level Javadoc explaining the two categories at a glance
  • Adds a method-change warning to redirect() Javadoc pointing developers to 307/308 when method preservation is needed
  • No logic changes

Test plan

  • All existing enkan-web tests pass (no logic change)

Closes #75

🤖 Generated with Claude Code

Add Javadoc to RedirectStatusCode enum constants and the redirect() method
explaining which codes change the request method (301/302/303) and which
preserve it (307/308), with references to RFC 7231 §6.4 and RFC 7538 §3.

Closes #75

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Documents redirect status code semantics in HttpResponseUtils to help developers choose between method-changing (301/302/303) and method-preserving (307/308) redirects, addressing Issue #75.

Changes:

  • Added enum-level and per-constant Javadoc for RedirectStatusCode with RFC references.
  • Updated HttpResponseUtils.redirect() Javadoc to warn about redirect-induced request method changes and recommend 307/308 when needed.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +32 to +34
* <p>Codes 301, 302, and 303 are <em>method-changing</em>: user agents MAY (and in practice always do)
* resubmit the request as GET regardless of the original method (RFC 7231 §6.4.2–6.4.4).
* Use 303 when you explicitly want a POST-to-GET redirect after a form submission.
Copilot AI Mar 8, 2026
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The enum-level Javadoc overstates the RFC semantics: for 301/302 the spec only allows changing POST to GET (not “regardless of the original method”), and it’s not accurate to say user agents “always” resubmit as GET (many non-browser clients preserve the method or make it configurable). Consider rephrasing to something like “browsers commonly change POST to GET for 301/302; 303 explicitly redirects to a GET/HEAD request” to keep this aligned with RFC 7231 §6.4.2–6.4.4.

Suggested change
* <p>Codes 301, 302, and 303 are <em>method-changing</em>: user agents MAY (and in practice always do)
* resubmit the request as GET regardless of the original method (RFC 7231 §6.4.2–6.4.4).
* Use 303 when you explicitly want a POST-to-GET redirect after a form submission.
* <p>For 301 and 302, RFC 7231 allows user agents to change a POST request to a GET when following
* the redirect, and browsers commonly do so in practice (RFC 7231 §6.4.2–6.4.3). Status code 303
* explicitly instructs the user agent to perform a GET (or HEAD) when following the redirect
* (RFC 7231 §6.4.4), and is typically used for POST-redirect-GET flows after form submission.

Copilot uses AI. Check for mistakes.
Comment on lines +89 to +92
* <p><strong>Method-change warning:</strong> status codes 301, 302, and 303 allow user agents to
* change the request method to GET when following the redirect. If you need the original method
* (e.g. POST or PUT) to be repeated at the new URI, use {@link RedirectStatusCode#TEMPORARY_REDIRECT}
* (307) or {@link RedirectStatusCode#PERMANENT_REDIRECT} (308) instead.
Copilot AI Mar 8, 2026
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The redirect() Javadoc says 301/302/303 “allow user agents to change the request method to GET”. That’s not quite accurate: 303 redirects to a GET/HEAD retrieval, while 301/302 only permit (and browsers commonly perform) a POST-to-GET rewrite. Tightening this wording would avoid implying that any method can be rewritten for 301/302 or that 303 is merely optional.

Copilot uses AI. Check for mistakes.
- 301/302: "MAY change POST to GET" (not "any method", not "always")
- 303: "MUST follow with GET or HEAD" (mandatory, not optional)
- Remove "all major browsers do" — accurate only for browsers, not all UA

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@kawasima kawasima left a comment
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed both:

  • Enum-level Javadoc: 301/302 now say "RFC 7231 permits user agents to change a POST to GET; browsers commonly do so" (not "always", not "any method"). 303 described as instructing GET/HEAD (mandatory, per reviewer suggestion).
  • redirect() method Javadoc: same distinction — 301/302 say "browsers commonly change POST to GET", 303 says "MUST follow with GET or HEAD".

Copilot AI left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


/**
* 303 See Other (RFC 7231 §6.4.4).
* The response to the redirect MUST be retrieved with GET.
Copilot AI Mar 8, 2026
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SEE_OTHER (303) enum constant Javadoc says the redirect "MUST be retrieved with GET", but elsewhere in this same file 303 is described as GET or HEAD. Please align these docs (e.g., mention GET or HEAD for 303) so the semantics are consistent.

Suggested change
* The response to the redirect MUST be retrieved with GET.
* The response to the redirect MUST be retrieved with GET or HEAD.

Copilot uses AI. Check for mistakes.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@kawasima kawasima left a comment
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed: SEE_OTHER constant Javadoc now says "GET or HEAD" to match the wording in the redirect() method Javadoc and RFC 7231 §6.4.4.

@kawasima
kawasima merged commit d04e941 into develop Mar 8, 2026
@kawasima
kawasima deleted the fix/rfc7231-redirect-status-javadoc branch March 8, 2026 05:27
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.

2 participants

0