Home / Function/ rebuild_method() — requests Function Reference

rebuild_method() — requests Function Reference

Architecture documentation for the rebuild_method() function in sessions.py from the requests codebase.

Entity Profile

Dependency Diagram

graph TD
  16c8903e_3ca3_7db8_eb77_e4f913e304f4["rebuild_method()"]
  29cd946c_8c0d_e37c_acb9_dfb2b83bf42b["SessionRedirectMixin"]
  16c8903e_3ca3_7db8_eb77_e4f913e304f4 -->|defined in| 29cd946c_8c0d_e37c_acb9_dfb2b83bf42b
  cbf6862f_d124_817f_3342_f1142c276f25["resolve_redirects()"]
  cbf6862f_d124_817f_3342_f1142c276f25 -->|calls| 16c8903e_3ca3_7db8_eb77_e4f913e304f4
  style 16c8903e_3ca3_7db8_eb77_e4f913e304f4 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/requests/sessions.py lines 334–354

    def rebuild_method(self, prepared_request, response):
        """When being redirected we may want to change the method of the request
        based on certain specs or browser behavior.
        """
        method = prepared_request.method

        # https://tools.ietf.org/html/rfc7231#section-6.4.4
        if response.status_code == codes.see_other and method != "HEAD":
            method = "GET"

        # Do what the browsers do, despite standards...
        # First, turn 302s into GETs.
        if response.status_code == codes.found and method != "HEAD":
            method = "GET"

        # Second, if a POST is responded to with a 301, turn it into a GET.
        # This bizarre behaviour is explained in Issue 1704.
        if response.status_code == codes.moved and method == "POST":
            method = "GET"

        prepared_request.method = method

Domain

Subdomains

Frequently Asked Questions

What does rebuild_method() do?
rebuild_method() is a function in the requests codebase, defined in src/requests/sessions.py.
Where is rebuild_method() defined?
rebuild_method() is defined in src/requests/sessions.py at line 334.
What calls rebuild_method()?
rebuild_method() is called by 1 function(s): resolve_redirects.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free