MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / _forward_proxy_raw

Function _forward_proxy_raw

e2e/python/test_sandbox_policy.py:255–276  ·  view source on GitHub ↗

Return a closure that sends a forward proxy request (no server needed). For testing deny cases — sends the request and returns whatever the proxy responds with.

()

Source from the content-addressed store, hash-verified

253
254
255def _forward_proxy_raw():
256 """Return a closure that sends a forward proxy request (no server needed).
257
258 For testing deny cases — sends the request and returns whatever the proxy
259 responds with.
260 """
261
262 def fn(proxy_host, proxy_port, target_url):
263 import socket
264 from urllib.parse import urlparse
265
266 conn = socket.create_connection((proxy_host, int(proxy_port)), timeout=10)
267 try:
268 parsed = urlparse(target_url)
269 host_header = parsed.netloc or parsed.hostname
270 req = f"GET {target_url} HTTP/1.1\r\nHost: {host_header}\r\n\r\n"
271 conn.sendall(req.encode())
272 return conn.recv(4096).decode("latin1")
273 finally:
274 conn.close()
275
276 return fn
277
278
279def _proxy_connect_then_http_with_server():

Calls

no outgoing calls

Tested by

no test coverage detected