Clarified error when header value is None (#3312)
Co-authored-by: Zanie Blue <contact@zanie.dev>
This commit is contained in:
parent
2e01aa0075
commit
49d74a2e7f
@ -50,6 +50,8 @@ def normalize_header_value(value: str | bytes, encoding: str | None = None) -> b
|
||||
"""
|
||||
if isinstance(value, bytes):
|
||||
return value
|
||||
if not isinstance(value, str):
|
||||
raise TypeError(f"Header value must be str or bytes, not {type(value)}")
|
||||
return value.encode(encoding or "ascii")
|
||||
|
||||
|
||||
|
||||
@ -177,6 +177,14 @@ def test_header_does_not_exist():
|
||||
del headers["baz"]
|
||||
|
||||
|
||||
def test_header_with_incorrect_value():
|
||||
with pytest.raises(
|
||||
TypeError,
|
||||
match=f"Header value must be str or bytes, not {type(None)}",
|
||||
):
|
||||
httpx.Headers({"foo": None}) # type: ignore
|
||||
|
||||
|
||||
def test_host_with_auth_and_port_in_url():
|
||||
"""
|
||||
The Host header should only include the hostname, or hostname:port
|
||||
|
||||
Loading…
Reference in New Issue
Block a user