twisted / treq

Python requests like API built on top of Twisted's HTTP client.
Other
585 stars 137 forks source link

treq.collect() should close the HTTP transport when the collector function throws an exception #347

Closed itamarst closed 1 year ago

itamarst commented 2 years ago

If the collector function throws an exception, that means there is no way to handle remaining body data. In some cases this may actually be a deliberate indication that the response is no good; for example, I implemented a length-constrained variant of treq.content(), and if the body exceeds that it's indication of a buggy or malicious server.

As such, the only reasonable thing to do in this situation is to close the transport.