build_digest_header() — requests Function Reference
Architecture documentation for the build_digest_header() function in auth.py from the requests codebase.
Entity Profile
Dependency Diagram
graph TD 7a5e3fcd_3d53_bb5a_33e1_2ec03991bb2c["build_digest_header()"] aa32083c_418b_f1ff_9e66_cf1a12e8a8ee["HTTPDigestAuth"] 7a5e3fcd_3d53_bb5a_33e1_2ec03991bb2c -->|defined in| aa32083c_418b_f1ff_9e66_cf1a12e8a8ee 351a1e00_cb4e_af8e_1ed9_e33664efe05e["handle_401()"] 351a1e00_cb4e_af8e_1ed9_e33664efe05e -->|calls| 7a5e3fcd_3d53_bb5a_33e1_2ec03991bb2c 19624f9a_1446_1a92_8704_bca792b9b1fa["__call__()"] 19624f9a_1446_1a92_8704_bca792b9b1fa -->|calls| 7a5e3fcd_3d53_bb5a_33e1_2ec03991bb2c b59a42f3_d82f_81a3_c550_b1cea1222004["get()"] 7a5e3fcd_3d53_bb5a_33e1_2ec03991bb2c -->|calls| b59a42f3_d82f_81a3_c550_b1cea1222004 style 7a5e3fcd_3d53_bb5a_33e1_2ec03991bb2c fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/requests/auth.py lines 126–234
def build_digest_header(self, method, url):
"""
:rtype: str
"""
realm = self._thread_local.chal["realm"]
nonce = self._thread_local.chal["nonce"]
qop = self._thread_local.chal.get("qop")
algorithm = self._thread_local.chal.get("algorithm")
opaque = self._thread_local.chal.get("opaque")
hash_utf8 = None
if algorithm is None:
_algorithm = "MD5"
else:
_algorithm = algorithm.upper()
# lambdas assume digest modules are imported at the top level
if _algorithm == "MD5" or _algorithm == "MD5-SESS":
def md5_utf8(x):
if isinstance(x, str):
x = x.encode("utf-8")
return hashlib.md5(x).hexdigest()
hash_utf8 = md5_utf8
elif _algorithm == "SHA":
def sha_utf8(x):
if isinstance(x, str):
x = x.encode("utf-8")
return hashlib.sha1(x).hexdigest()
hash_utf8 = sha_utf8
elif _algorithm == "SHA-256":
def sha256_utf8(x):
if isinstance(x, str):
x = x.encode("utf-8")
return hashlib.sha256(x).hexdigest()
hash_utf8 = sha256_utf8
elif _algorithm == "SHA-512":
def sha512_utf8(x):
if isinstance(x, str):
x = x.encode("utf-8")
return hashlib.sha512(x).hexdigest()
hash_utf8 = sha512_utf8
KD = lambda s, d: hash_utf8(f"{s}:{d}") # noqa:E731
if hash_utf8 is None:
return None
# XXX not implemented yet
entdig = None
p_parsed = urlparse(url)
#: path is request-uri defined in RFC 2616 which should not be empty
path = p_parsed.path or "/"
if p_parsed.query:
path += f"?{p_parsed.query}"
A1 = f"{self.username}:{realm}:{self.password}"
A2 = f"{method}:{path}"
HA1 = hash_utf8(A1)
HA2 = hash_utf8(A2)
if nonce == self._thread_local.last_nonce:
self._thread_local.nonce_count += 1
else:
self._thread_local.nonce_count = 1
ncvalue = f"{self._thread_local.nonce_count:08x}"
s = str(self._thread_local.nonce_count).encode("utf-8")
s += nonce.encode("utf-8")
s += time.ctime().encode("utf-8")
s += os.urandom(8)
cnonce = hashlib.sha1(s).hexdigest()[:16]
if _algorithm == "MD5-SESS":
Domain
Subdomains
Defined In
Calls
Called By
Source
Frequently Asked Questions
What does build_digest_header() do?
build_digest_header() is a function in the requests codebase, defined in src/requests/auth.py.
Where is build_digest_header() defined?
build_digest_header() is defined in src/requests/auth.py at line 126.
What does build_digest_header() call?
build_digest_header() calls 1 function(s): get.
What calls build_digest_header()?
build_digest_header() is called by 2 function(s): __call__, handle_401.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free