shazow/urllib3 — pull request #139 by stanvit (2013-01-09 02:52:21+00:00)
Title: HTTPS proxy support (issue #50)

This Pull Request resolves #50 adding HTTPS (CONNECT) proxy support to ProxyManager with minimal API and code changes.

A short summary of the changes:

- ProxyManager is a subclass of PoolManager now and its logic has been changed completely, though its constructor still accepts HTTPConnectionPool as the main argument so it's backwards compatible
- Tiny change to VerifiedHTTPSConnection.connect() that introduces CONNECT tunneling support (copied from HTTPConnection.connect() code)
- HTTPSConnectionPool._new_conn() has been changed, but its logic for non-proxied connections stays the same
- HTTPSConnectionPool._new_conn() actually establishes the connection for proxied requests by calling HTTPSConnection.connect(), otherwise Host: header is set improperly due to httplib logic. As stated above, the behavior for non-proxied requests hasn't changed
- [tornado-proxy](https://github.com/senko/tornado-proxy) has been added for tests
- TornadoServerThread has been changed a bit - now it's possible to run multiple server threads in a single test case
- Added proxy tests
- Docs updated

All tests run fine with Python 2.6, 2.7 and 3.2 on Mac OS 10.7.5, except for sporadic timeouts and SSL errors that occur against the unpatched library as well (and should be fixed separately). The code doesn't introduce any new regressions.

Possible TODOs and improvements:

- Proxy authentication (though that could be another libraries' responsibility, like [requests](https://github.com/kennethreitz/requests))
- When accepting proxy_pool as the first argument for ProxyManager, copy all pool properties and use them for other pool instances generation or even use it as the pool for HTTP proxy requests
- Usage of HTTPConnectionPool and, especially, HTTPSConnectionPool against proxy isn't really clear and requires some external logic - much like ProxyManager.connection_from_host()