Files
httrack/tests/proxy-connect-server.py
Xavier Roche 93ec06f404 Make the test servers' proxytestlib import survive python3 -P
The three test servers import proxytestlib from their own directory, which works because Python puts the running script's directory on sys.path. PYTHONSAFEPATH (python3 -P) drops it and the import fails. Nothing in the harness or CI sets it, and the failure is loud rather than a silent skip, so this is belt-and-braces for anyone running a server by hand under -P.

Each server now inserts its own directory before the import. Verified by reproducing the ModuleNotFoundError first, then confirming all three announce ready under -P afterwards. No file in tests/ shadows a stdlib module, so the extra sys.path entry is inert in the normal case.
2026-07-16 18:01:30 +02:00

38 lines
1.4 KiB
Python

#!/usr/bin/env python3
"""Local CONNECT-only proxy + plain-HTTP origin for the issue #564 test.
Models a tor HTTPTunnelPort: an HTTP proxy that honours CONNECT and rejects
every other method with 501 (the classic absolute-URI form a normal HTTP proxy
accepts). Fronting it is a plain-HTTP origin. The proxy logs each request line
(and any Proxy-Authorization); the origin logs its request line and headers.
That lets the test assert a plain-http crawl tunneled through CONNECT, arrived
origin-form (not "GET http://host/..."), and never leaked proxy credentials.
Proxy modes (argv[2], 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-connect-server.py <logdir> [mode]
Prints "ORIGIN <port>", "PROXY <port>", then "ready" (one per line) on stdout.
"""
import os
import sys
# python3 -P (PYTHONSAFEPATH) drops the script's own directory from sys.path
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import proxytestlib # noqa: E402
ORIGIN_BODY = b"<html><body>ORIGIN-PAGE-564</body></html>"
def main():
logdir = sys.argv[1]
mode = sys.argv[2] if len(sys.argv) > 2 else "ok"
proxytestlib.serve(logdir, ORIGIN_BODY, 80, mode)
if __name__ == "__main__":
main()