Support FIPS-enforced Python builds without `hashlib.md5` in `DigestAuth`
Merged
MW
2mo ago+59+59+01234567890123456789-11-11-01234567890123456789
Summary
MD5 is not a FIPS-approved algorithm, and some FIPS-enforced Python images remove hashlib.md5 entirely. Because DigestAuth references hashlib.md5 in a class-level dictionary, this causes an AttributeError at import time, making the entire httpx2 library unusable on these environments, even if MD5 digest auth is never used.
This change conditionally registers the MD5 algorithm entries only when hashlib.md5 is present, so httpx2 can be imported on FIPS-enforced environments while preserving full MD5 digest auth support elsewhere. When a server requests an unavailable algorithm, a clear ProtocolError is raised instead of an opaque KeyError.
Discussion: https://github.com/pydantic/httpx2/discussions/1094
Checklist
- I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
- I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
- I've updated the documentation accordingly.
- (No documentation to update?)