Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a48d9ea

Browse files
committed
improve set_tunnel docs (closes #11448)
Patch by Ryan Kelly, karl, and Nikolaus Rath.
1 parent fda3355 commit a48d9ea

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

Doc/library/http.client.rst

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,11 +451,25 @@ HTTPConnection Objects
451451

452452
.. method:: HTTPConnection.set_tunnel(host, port=None, headers=None)
453453

454-
Set the host and the port for HTTP Connect Tunnelling. Normally used when it
455-
is required to a HTTPS Connection through a proxy server.
454+
Set the host and the port for HTTP Connect Tunnelling. This allows running
455+
the connection through a proxy server.
456456

457-
The headers argument should be a mapping of extra HTTP headers to send
458-
with the CONNECT request.
457+
The host and port arguments specify the endpoint of the tunneled connection
458+
(i.e. the address included in the CONNECT request, *not* the address of the
459+
proxy server).
460+
461+
The headers argument should be a mapping of extra HTTP headers to send with
462+
the CONNECT request.
463+
464+
For example, to tunnel through a HTTPS proxy server running locally on port
465+
8080, we would pass the address of the proxy to the :class:`HTTPSConnection`
466+
constructor, and the address of the host that we eventually want to reach to
467+
the :meth:`~HTTPConnection.set_tunnel` method::
468+
469+
>>> import http.client
470+
>>> conn = http.client.HTTPSConnection("localhost", 8080)
471+
>>> conn.set_tunnel("www.python.org")
472+
>>> conn.request("HEAD","/index.html")
459473

460474
.. versionadded:: 3.2
461475

0 commit comments

Comments
 (0)