Skip to content

Commit

Permalink
fix(http): Fetch and HTTP spec clarifications with 301 and 302 status…
Browse files Browse the repository at this point in the history
… codes (mdn#35294)

* fix status codes

* minor fix

* Update files/en-us/web/http/status/302/index.md

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update index.md

* Update index.md

* review comments

Co-authored-by: Brian Thomas Smith <[email protected]>

* review comments

Co-authored-by: Brian Thomas Smith <[email protected]>

---------

Co-authored-by: Gagan Bhullar <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Joshua Chen <[email protected]>
Co-authored-by: Brian Thomas Smith <[email protected]>
  • Loading branch information
5 people authored Sep 3, 2024
1 parent d5ded97 commit 6d81ba6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions files/en-us/web/http/status/301/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ A browser receiving this status will automatically request the resource at the U
Search engines receiving this response will attribute links to the original URL to the redirected resource, passing the {{Glossary("SEO")}} ranking to the new URL.

> [!NOTE]
> Although the [specification](#specifications) requires the request method and the body to remain unchanged when redirection is performed, not all user-agents meet this requirement.
> Use the `301` code only as a response for {{HTTPMethod("GET")}} or {{HTTPMethod("HEAD")}} methods and use the {{HTTPStatus("308", "308 Permanent Redirect")}} for other methods (typically {{HTTPMethod("POST")}}), as altering the method when handling `308` responses is explicitly prohibited.
> In the [Fetch Standard](https://fetch.spec.whatwg.org/#http-redirect-fetch), when a user agent receives a `301` in response to a {{HTTPMethod("POST")}} request, it uses the {{HTTPMethod("GET")}} method in the subsequent redirection request, as permitted by the HTTP [specification](#specifications).
> To avoid user agents modifying the request, use {{HTTPStatus("308", "308 Permanent Redirect")}} instead, as altering the method after a `308` response is prohibited.
## Status

Expand Down
6 changes: 3 additions & 3 deletions files/en-us/web/http/status/302/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ A browser receiving this status will automatically request the resource at the U
Search engines receiving this response will not attribute links to the original URL to the new resource, meaning no {{Glossary("SEO")}} value is transferred to the new URL.

> [!NOTE]
> Although the [specification](#specifications) requires the method (and the body) not to be altered when the redirection is performed, not all user-agents meet this requirement.
> Use the `302` code only as a response for {{HTTPMethod("GET")}} or {{HTTPMethod("HEAD")}} methods and use {{HTTPStatus("307", "307 Temporary Redirect")}} otherwise, as the method change is explicitly prohibited in that case.
> In the [Fetch Standard](https://fetch.spec.whatwg.org/#http-redirect-fetch), when a user agent receives a `302` in response to a {{HTTPMethod("POST")}} request, it uses the {{HTTPMethod("GET")}} method in the subsequent redirection request, as permitted by the HTTP [specification](#specifications).
> To avoid user agents modifying the request, use {{HTTPStatus("307", "307 Temporary Redirect")}} instead, as altering the method after a `307` response is prohibited.
>
> In cases where you want the method used to be changed to {{HTTPMethod("GET")}}, use {{HTTPStatus("303", "303 See Other")}} instead.
> In cases where you want any request method to be changed to {{HTTPMethod("GET")}}, use {{HTTPStatus("303", "303 See Other")}}.
> This is useful when you want to give a response to a {{HTTPMethod("PUT")}} method that is not the uploaded resource but a confirmation message such as: "you successfully uploaded XYZ".
## Status
Expand Down

0 comments on commit 6d81ba6

Please sign in to comment.