MCPcopy
hub / github.com/urllib3/urllib3 / request_handler

Method request_handler

test/contrib/test_socks.py:733–764  ·  test/contrib/test_socks.py::TestSOCKSWithTLS.request_handler
(listener: socket.socket)

Source from the content-addressed store, hash-verified

731 @pytest.mark.skipif(not HAS_SSL, reason=class="st">"No TLS available")
732 def test_basic_request(self) -> None:
733 def request_handler(listener: socket.socket) -> None:
734 sock = listener.accept()[0]
735
736 handler = handle_socks5_negotiation(sock, negotiate=False)
737 addr, port = next(handler)
738
739 assert addr == bclass="st">"localhost"
740 assert port == 443
741 with pytest.raises(StopIteration):
742 handler.send(True)
743
744 class="cm"># Wrap in TLS
745 context = better_ssl.SSLContext(ssl.PROTOCOL_SSLv23) class="cm"># type: ignore[misc]
746 context.load_cert_chain(DEFAULT_CERTS[class="st">"certfile"], DEFAULT_CERTS[class="st">"keyfile"])
747 tls = context.wrap_socket(sock, server_side=True)
748 buf = bclass="st">""
749
750 while True:
751 buf += tls.recv(65535)
752 if buf.endswith(bclass="st">"\r\n\r\n"):
753 break
754
755 assert buf.startswith(bclass="st">"GET / HTTP/1.1\r\n")
756
757 tls.sendall(
758 bclass="st">"HTTP/1.1 200 OK\r\n"
759 bclass="st">"Server: SocksTestServer\r\n"
760 bclass="st">"Content-Length: 0\r\n"
761 bclass="st">"\r\n"
762 )
763 tls.close()
764 sock.close()
765
766 self._start_server(request_handler)
767 proxy_url = fclass="st">"socks5h://{self.host}:{self.port}"

Callers

nothing calls this directly

Calls 7

load_cert_chainMethod · 0.80
wrap_socketMethod · 0.80
sendMethod · 0.45
recvMethod · 0.45
sendallMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected