httpx
httpx copied to clipboard
Include header name in encoding error messages
Summary
When headers contain non-ASCII characters, the error message now includes the header name to make debugging easier.
Before:
httpx.Headers({"Authorization": "Bearer valid", "X-Custom": "안녕"})
# UnicodeEncodeError: 'ascii' codec can't encode characters...
# Which header failed?
After:
httpx.Headers({"Authorization": "Bearer valid", "X-Custom": "안녕"})
# UnicodeEncodeError: Header 'X-Custom' value contains non-ASCII characters
# Clear which header is the problem
Changes
- Added optional header_name parameter to _normalize_header_key and _normalize_header_value
- Updated error messages to include header name when encoding fails
- Added tests for both header key and value encoding errors
related #3400