Skip to content
Myr

Clean up response interface

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

authored by Tom Christie · committed by Tom Christie · parent d7619a9 · Browse files · 1 file+28 added−14 removed
This commit

State

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

Diff stats

1 file+28 added−14 removed

  • other:+28 added−14 removed

1 file+28 added−14 removed

modified:httpcore/models.py+28 added-14 removed
322 unmodified lines
323 self.on_close = on_close324 self.is_closed = False325 self.is_streamed = False326327 decoders = [] # type: typing.List[Decoder]328 value = self.headers.get("content-encoding", "identity")329 for part in value.split(","):330 part = part.strip().lower()331 decoder_cls = SUPPORTED_DECODERS[part]332 decoders.append(decoder_cls())333334 if len(decoders) == 0:335 self.decoder = IdentityDecoder() # type: Decoder336 elif len(decoders) == 1:337 self.decoder = decoders[0]338 else:339 self.decoder = MultiDecoder(decoders)340327 if isinstance(body, bytes):328 self.is_closed = True329 self.body = self.decoder.decode(body) + self.decoder.flush()330 else:
4 unmodified lines
335 self.next = None # typing.Optional[typing.Callable]336337 @property338 def url(self) -> typing.Optional[URL]:339 """340 Returns the URL for which the request was made.341342 Requires that `request` was provided when instantiating the response.343 """344 return None if self.request is None else self.request.url345346 @property347 def decoder(self) -> Decoder:348 """349 Returns a decoder instance which can be used to decode the raw byte350 content, depending on the Content-Encoding used in the response.351 """352 if not hasattr(self, "_decoder"):353 decoders = [] # type: typing.List[Decoder]354 value = self.headers.get("content-encoding", "identity")355 for part in value.split(","):356 part = part.strip().lower()357 decoder_cls = SUPPORTED_DECODERS[part]358 decoders.append(decoder_cls())359360 if len(decoders) == 1:361 self._decoder = decoders[0]362 elif len(decoders) > 1:363 self._decoder = MultiDecoder(decoders)364 else:365 self._decoder = IdentityDecoder()366367 return self._decoder368369 async def read(self) -> bytes:370 """371 Read and return the response content.372 """
55 unmodified lines