Files
httrack/tests/proxy-https-server.py
Xavier Roche d100cd42e9 Share the proxy test servers' duplicated code in proxytestlib.py
proxy-https-server.py (#85) and proxy-connect-server.py (#564) were ~90%
identical: the CONNECT proxy, the relay and the origin were copies, with
only the origin body, the TLS wrap and the argv shape differing. Move the
common half into tests/proxytestlib.py; each server is now a docstring
plus a serve() call. socks5-server.py reuses the relay too, but keeps its
own origin, which is specialised for keep-alive reuse and subpages.

The shared origin always logs the request line (it was proxy-connect only);
harmless for #85, which only asserts no Proxy-Authorization reaches it.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Xavier Roche <roche@httrack.com>
2026-07-16 09:41:28 +02:00

33 lines
1.2 KiB
Python

#!/usr/bin/env python3
"""Local CONNECT proxy + self-signed HTTPS origin for the issue #85 test.
Starts a TLS origin server and an HTTP proxy that honours CONNECT, on ephemeral
ports. Every request line the proxy receives (and any Proxy-Authorization) is
appended to the proxy log; every header the origin receives over the tunnel is
appended to the origin log. That lets the test assert both that an https crawl
tunneled through the proxy and that proxy credentials never leaked to the origin.
Proxy modes (argv[3], default "ok"):
ok - honour CONNECT and tunnel to the origin
flood - answer 200 then stream headers forever with no blank line, to exercise
the client's bound on the proxy response (must not hang the crawl)
Usage: proxy-https-server.py <cert.pem> <logdir> [mode]
Prints "ORIGIN <port>", "PROXY <port>", then "ready" (one per line) on stdout.
"""
import sys
import proxytestlib
ORIGIN_BODY = b"<html><body>ORIGIN-PAGE-85</body></html>"
def main():
certfile, logdir = sys.argv[1], sys.argv[2]
mode = sys.argv[3] if len(sys.argv) > 3 else "ok"
proxytestlib.serve(logdir, ORIGIN_BODY, 443, mode, certfile=certfile)
if __name__ == "__main__":
main()