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

Function apply_missing_repeated_headers

httpie/client.py:233–260  ·  view source on GitHub ↗

Update the given `prepared_request`'s headers with the original ones. This allows the requests to be prepared as usual, and then later merged with headers that are specified multiple times.

(
    original_headers: HTTPHeadersDict,
    prepared_request: requests.PreparedRequest
)

Source from the content-addressed store, hash-verified

231
232
233def apply_missing_repeated_headers(
234 original_headers: HTTPHeadersDict,
235 prepared_request: requests.PreparedRequest
236) -> None:
237 """Update the given `prepared_request`'s headers with the original
238 ones. This allows the requests to be prepared as usual, and then later
239 merged with headers that are specified multiple times."""
240
241 new_headers = HTTPHeadersDict(prepared_request.headers)
242 for prepared_name, prepared_value in prepared_request.headers.items():
243 if prepared_name not in original_headers:
244 continue
245
246 original_keys, original_values = zip(*filter(
247 lambda item: item[0].casefold() == prepared_name.casefold(),
248 original_headers.items()
249 ))
250
251 if prepared_value not in original_values:
252 # If the current value is not among the initial values
253 # set for this field, then it means that this field got
254 # overridden on the way, and we should preserve it.
255 continue
256
257 new_headers.popone(prepared_name)
258 new_headers.update(zip(original_keys, original_values))
259
260 prepared_request.headers = new_headers
261
262
263def make_default_headers(args: argparse.Namespace) -> HTTPHeadersDict:

Callers 1

transform_headersFunction · 0.85

Calls 3

HTTPHeadersDictClass · 0.85
itemsMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected