MCPcopy
hub / github.com/psf/requests / prepare_content_length

Method prepare_content_length

src/requests/models.py:652–666  ·  view source on GitHub ↗

Prepare Content-Length header based on request method and body

(self, body: _t.BodyType)

Source from the content-addressed store, hash-verified

650 self.body = body # type: ignore[assignment] # body transforms from DataType to BodyType
651
652 def prepare_content_length(self, body: _t.BodyType) -> None:
653 """Prepare Content-Length header based on request method and body"""
654 if body is not None:
655 length = super_len(body)
656 if length:
657 # If length exists, set it. Otherwise, we fallback
658 # to Transfer-Encoding: chunked.
659 self.headers["Content-Length"] = builtin_str(length)
660 elif (
661 self.method not in ("GET", "HEAD")
662 and self.headers.get("Content-Length") is None
663 ):
664 # Set Content-Length to 0 for methods that can have a body
665 # but don't provide one. (i.e. not GET or HEAD)
666 self.headers["Content-Length"] = "0"
667
668 def prepare_auth(
669 self,

Callers 2

prepare_bodyMethod · 0.95
prepare_authMethod · 0.95

Calls 2

super_lenFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected