Martin Panter added the comment:

I believe this also affects Python 3; see Issue 24333.

I think making the CONNECT response object available to the caller is the right 
general approach. But I really dislike raising an exception that holds a socket 
connection to be closed. (I know this is already done with 
urllib.error.HTTPError; let’s not repeat this in the “http.client” module!)

Ideally, at the “http.client” level I would prefer to avoid all the special 
set_tunnel() calls, and use the usual request() and getresponse() API to make 
the CONNECT request. This way the response status and header fields would be 
available just like any other response. For this approach to work, we would 
probably need to add a new HTTPConnection.detach() method that released the 
original socket reader and writer, and add a way to create a new HTTPConnection 
instance using these socket objects. This enhancement probably wouldn’t be 
appropriate for Python 2 or a bug fix release. But it seems the cleanest 
approach to me, and may also allow using HTTPConnection with the Upgrade header 
(e.g. for opportunistic encryption, HTTP 2, Web etc), and proxying non-HTTP 
connections, as bonuses.

A less revolutionary approach might be to add a HTTPSConnection.tunnel() 
method, that always returns the proxy’s response, but only does the SSL 
wrapping for a successful response.

----------
nosy: +vadmium
versions: +Python 3.4, Python 3.5, Python 3.6

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue7291>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to