kennethreitz/requests — pull request #1669 by Lukasa (2013-10-13 08:59:50+00:00)
Title: [WIP] Better chunked handling.

Following #1642, I think we should treat urllib3's pooled connections better when we manage them ourselves. This PR provides the following extra functionality:

- Clean up connections when we hit problems during chunked upload, rather than leaking them.
- Return connections to the pool when a chunked upload is successful, rather than leaking it.

The diff is a little unclear, so let me clarify: I wrapped most of the chunked code in a `try` block, then added a catch-everything exception handler that will attempt to close the connection if we hit it. Otherwise, we'll return the presumably-fine connection to the pool.

I'd like some code review on this. @sigmavirus24, can you confirm this is doing what I think it is, and can you give me some suggestions for how best to test it? @shazow, if you have time, can you confirm that I'm obeying the semantics of the urllib3 connection pool? (e.g. should I check if we get a `Connection: close` header on the response?