Skip to content
Myr

Clarified error when header value is None (#3312)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Polina Beskorovainaia · committed by GitHub · parent 2e01aa0 · Browse files · 2 files+10 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Zanie Blue <contact@zanie.dev>

Diff stats

2 files+10 added−0 removed

  • tests:+8 added−0 removed
  • other:+2 added−0 removed

2 files+10 added−0 removed

modified:httpx/_utils.py+2 added
48 unmodified lines
49 Coerce str/bytes into a strictly byte-wise HTTP header value.50 """51 if isinstance(value, bytes):52 return value53 if not isinstance(value, str):54 raise TypeError(f"Header value must be str or bytes, not {type(value)}")55 return value.encode(encoding or "ascii")565758def primitive_value_to_str(value: PrimitiveData) -> str:
384 unmodified lines
modified:tests/client/test_headers.py+8 added
175 unmodified lines
176 with pytest.raises(KeyError):177 del headers["baz"]178179180def test_header_with_incorrect_value():181 with pytest.raises(182 TypeError,183 match=f"Header value must be str or bytes, not {type(None)}",184 ):185 httpx.Headers({"foo": None}) # type: ignore186187188def test_host_with_auth_and_port_in_url():189 """190 The Host header should only include the hostname, or hostname:port191 (for non-default ports only). Any userinfo or default port should not
46 unmodified lines