Skip to content
Myr

Stream tweak (#1607)

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

authored by Tom Christie · committed by GitHub · parent 760af43 · Browse files · 2 files+21 added−23 removed
This commit

State

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

Diff stats

2 files+21 added−23 removed

  • other:+21 added−23 removed

2 files+21 added−23 removed

modified:httpx/_client.py+2 added-3 removed
495 unmodified lines
496 # Strip Authorization headers when responses are redirected away from497 # the origin.498 headers.pop("Authorization", None)499500 # Remove the Host header, so that a new one will be auto-populated on501 # the request instance.502 headers.pop("Host", None)500 # Update the Host header.501 headers["Host"] = url.netloc.decode("ascii")502503 if method != request.method and method == "GET":504 # If we've switch to a 'GET' request, then strip any headers which505 # are only relevant to the request body.
1413 unmodified lines
modified:httpx/_models.py+19 added-20 removed
1087 unmodified lines
1088 self.headers = Headers(headers)1089 if cookies:1090 Cookies(cookies).set_cookie_header(self)10911092 if stream is not None:1092 if stream is None:1093 headers, stream = encode_request(content, data, files, json)1094 self._prepare(headers)1095 self.stream = stream1096 # Load the request body, except for streaming content.1097 if isinstance(stream, ByteStream):1098 self.read()1099 else:1100 # There's an important distinction between `Request(content=...)`,1101 # and `Request(stream=...)`.1102 #1096 # Using `content=...` implies automatically populated content headers,1097 # of either `Content-Length: ...` or `Transfer-Encoding: chunked`.1103 # Using `content=...` implies automatically populated `Host` and content1104 # headers, of either `Content-Length: ...` or `Transfer-Encoding: chunked`.1105 #1099 # Using `stream=...` will not automatically include any content headers.1106 # Using `stream=...` will not automatically include *any* auto-populated headers.1107 #1108 # As an end-user you don't really need `stream=...`. It's only1109 # useful when:1110 #1111 # * Preserving the request stream when copying requests, eg for redirects.1112 # * Creating request instances on the *server-side* of the transport API.1113 self.stream = stream1107 self._prepare({})1108 else:1109 headers, stream = encode_request(content, data, files, json)1110 self._prepare(headers)1111 self.stream = stream1112 # Load the request body, except for streaming content.1113 if isinstance(stream, ByteStream):1114 self.read()11141115 def _prepare(self, default_headers: typing.Dict[str, str]) -> None:1116 for key, value in default_headers.items():1117 # Ignore Transfer-Encoding if the Content-Length has been set explicitly.
96 unmodified lines
12141215 self.is_closed = False1216 self.is_stream_consumed = False12171219 if stream is not None:1218 if stream is None:1219 headers, stream = encode_response(content, text, html, json)1220 self._prepare(headers)1221 self.stream = stream1222 if isinstance(stream, ByteStream):1223 # Load the response body, except for streaming content.1224 self.read()1225 else:1226 # There's an important distinction between `Response(content=...)`,1227 # and `Response(stream=...)`.1228 #1229 # Using `content=...` implies automatically populated content headers,
4 unmodified lines
1234 # As an end-user you don't really need `stream=...`. It's only1235 # useful when creating response instances having received a stream1236 # from the transport API.1237 self.stream = stream1232 else:1233 headers, stream = encode_response(content, text, html, json)1234 self._prepare(headers)1235 self.stream = stream1236 if isinstance(stream, ByteStream):1237 # Load the response body, except for streaming content.1238 self.read()12381239 self._num_bytes_downloaded = 012401241 def _prepare(self, default_headers: typing.Dict[str, str]) -> None:
602 unmodified lines