(headers: HTTPHeadersDict)
| 190 | |
| 191 | |
| 192 | def 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 | |
| 212 | def transform_headers( |
no test coverage detected