prepare_content_length() — requests Function Reference
Architecture documentation for the prepare_content_length() function in models.py from the requests codebase.
Entity Profile
Dependency Diagram
graph TD ad57bfe9_2bba_ea6e_5e85_44c51303ed35["prepare_content_length()"] c8cfcd0c_a36a_3124_6cd4_1516b06c63b3["PreparedRequest"] ad57bfe9_2bba_ea6e_5e85_44c51303ed35 -->|defined in| c8cfcd0c_a36a_3124_6cd4_1516b06c63b3 fdb744d2_4cc0_a0f9_c288_a0abeac5e58e["prepare_body()"] fdb744d2_4cc0_a0f9_c288_a0abeac5e58e -->|calls| ad57bfe9_2bba_ea6e_5e85_44c51303ed35 bea876a9_383a_fe0e_3e83_080ef6697c9f["prepare_auth()"] bea876a9_383a_fe0e_3e83_080ef6697c9f -->|calls| ad57bfe9_2bba_ea6e_5e85_44c51303ed35 afb5f427_a5f4_14c6_bceb_0bab74c9174b["super_len()"] ad57bfe9_2bba_ea6e_5e85_44c51303ed35 -->|calls| afb5f427_a5f4_14c6_bceb_0bab74c9174b 3429da06_bfa7_f55e_ca34_e7199d2cf1df["get()"] ad57bfe9_2bba_ea6e_5e85_44c51303ed35 -->|calls| 3429da06_bfa7_f55e_ca34_e7199d2cf1df style ad57bfe9_2bba_ea6e_5e85_44c51303ed35 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/requests/models.py lines 574–588
def prepare_content_length(self, body):
"""Prepare Content-Length header based on request method and body"""
if body is not None:
length = super_len(body)
if length:
# If length exists, set it. Otherwise, we fallback
# to Transfer-Encoding: chunked.
self.headers["Content-Length"] = builtin_str(length)
elif (
self.method not in ("GET", "HEAD")
and self.headers.get("Content-Length") is None
):
# Set Content-Length to 0 for methods that can have a body
# but don't provide one. (i.e. not GET or HEAD)
self.headers["Content-Length"] = "0"
Domain
Subdomains
Defined In
Calls
Called By
Source
Frequently Asked Questions
What does prepare_content_length() do?
prepare_content_length() is a function in the requests codebase, defined in src/requests/models.py.
Where is prepare_content_length() defined?
prepare_content_length() is defined in src/requests/models.py at line 574.
What does prepare_content_length() call?
prepare_content_length() calls 2 function(s): get, super_len.
What calls prepare_content_length()?
prepare_content_length() is called by 2 function(s): prepare_auth, prepare_body.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free