MCPcopy
hub / github.com/urllib3/urllib3 / test_basic_request

Method test_basic_request

test/contrib/test_socks.py:246–278  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

244 """
245
246 def test_basic_request(self) -> None:
247 def request_handler(listener: socket.socket) -> None:
248 sock = listener.accept()[0]
249
250 handler = handle_socks5_negotiation(sock, negotiate=False)
251 addr, port = next(handler)
252
253 assert addr == "16.17.18.19"
254 assert port == 80
255 with pytest.raises(StopIteration):
256 handler.send(True)
257
258 while True:
259 buf = sock.recv(65535)
260 if buf.endswith(b"\r\n\r\n"):
261 break
262
263 sock.sendall(
264 b"HTTP/1.1 200 OK\r\n"
265 b"Server: SocksTestServer\r\n"
266 b"Content-Length: 0\r\n"
267 b"\r\n"
268 )
269 sock.close()
270
271 self._start_server(request_handler)
272 proxy_url = f"socks5://{self.host}:{self.port}"
273 with socks.SOCKSProxyManager(proxy_url) as pm:
274 response = pm.request("GET", "http://16.17.18.19")
275
276 assert response.status == 200
277 assert response.data == b""
278 assert response.headers["Server"] == "SocksTestServer"
279
280 def test_local_dns(self) -> None:
281 def request_handler(listener: socket.socket) -> None:

Callers

nothing calls this directly

Calls 2

_start_serverMethod · 0.45
requestMethod · 0.45

Tested by

no test coverage detected