MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _tunnel

Method _tunnel

tools/python-3.11.9-amd64/Lib/http/client.py:923–957  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

921 return ip
922
923 def _tunnel(self):
924 connect = b"CONNECT %s:%d HTTP/1.0\r\n" % (
925 self._wrap_ipv6(self._tunnel_host.encode("ascii")),
926 self._tunnel_port)
927 headers = [connect]
928 for header, value in self._tunnel_headers.items():
929 headers.append(f"{header}: {value}\r\n".encode("latin-1"))
930 headers.append(b"\r\n")
931 # Making a single send() call instead of one per line encourages
932 # the host OS to use a more optimal packet size instead of
933 # potentially emitting a series of small packets.
934 self.send(b"".join(headers))
935 del headers
936
937 response = self.response_class(self.sock, method=self._method)
938 try:
939 (version, code, message) = response._read_status()
940
941 if code != http.HTTPStatus.OK:
942 self.close()
943 raise OSError(f"Tunnel connection failed: {code} {message.strip()}")
944 while True:
945 line = response.fp.readline(_MAXLINE + 1)
946 if len(line) > _MAXLINE:
947 raise LineTooLong("header line")
948 if not line:
949 # for sites which EOF without sending a trailer
950 break
951 if line in (b'\r\n', b'\n', b''):
952 break
953
954 if self.debuglevel > 0:
955 print('header:', line.decode())
956 finally:
957 response.close()
958
959 def connect(self):
960 """Connect to the host and port specified in __init__."""

Callers 4

connectMethod · 0.95
_prepare_connMethod · 0.95
connectMethod · 0.80
connectMethod · 0.80

Calls 14

_wrap_ipv6Method · 0.95
sendMethod · 0.95
closeMethod · 0.95
LineTooLongClass · 0.85
_read_statusMethod · 0.80
stripMethod · 0.80
printFunction · 0.50
encodeMethod · 0.45
itemsMethod · 0.45
appendMethod · 0.45
joinMethod · 0.45
readlineMethod · 0.45

Tested by

no test coverage detected