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.
()
| 253 | |
| 254 | |
| 255 | def _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 | |
| 279 | def _proxy_connect_then_http_with_server(): |
no outgoing calls
no test coverage detected