Co-authored-by: Zanie Blue <contact@zanie.dev>
"""
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")
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