MCPcopy
hub / github.com/encode/httpx / _normalize_header_value

Function _normalize_header_value

httpx/_models.py:74–82  ·  httpx/_models.py::_normalize_header_value

Coerce str/bytes into a strictly byte-wise HTTP header value.

(value: str | bytes, encoding: str | None = None)

Source from the content-addressed store, hash-verified

72
73
74def _normalize_header_value(value: str | bytes, encoding: str | None = None) -> bytes:
75 class="st">"""
76 Coerce str/bytes into a strictly byte-wise HTTP header value.
77 class="st">"""
78 if isinstance(value, bytes):
79 return value
80 if not isinstance(value, str):
81 raise TypeError(fclass="st">"Header value must be str or bytes, not {type(value)}")
82 return value.encode(encoding or class="st">"ascii")
83
84
85def _parse_content_type_charset(content_type: str) -> str | None:

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected