MCPcopy
hub / github.com/httpie/cli / finalize_headers

Function finalize_headers

httpie/client.py:192–209  ·  view source on GitHub ↗
(headers: HTTPHeadersDict)

Source from the content-addressed store, hash-verified

190
191
192def finalize_headers(headers: HTTPHeadersDict) -> HTTPHeadersDict:
193 final_headers = HTTPHeadersDict()
194 for name, value in headers.items():
195 if value is not None:
196 # “leading or trailing LWS MAY be removed without
197 # changing the semantics of the field value”
198 # <https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html>
199 # Also, requests raises `InvalidHeader` for leading spaces.
200 value = value.strip()
201 if isinstance(value, str):
202 # See <https://github.com/httpie/cli/issues/212>
203 value = value.encode()
204 elif name.lower() in SKIPPABLE_HEADERS:
205 # Some headers get overwritten by urllib3 when set to `None`
206 # and should be replaced with the `SKIP_HEADER` constant.
207 value = SKIP_HEADER
208 final_headers.add(name, value)
209 return final_headers
210
211
212def transform_headers(

Callers 1

make_request_kwargsFunction · 0.85

Calls 3

addMethod · 0.95
HTTPHeadersDictClass · 0.85
itemsMethod · 0.45

Tested by

no test coverage detected