xref: /llvm-project/llvm/test/tools/llvm-debuginfod-find/Inputs/capture_req.py (revision b71edfaa4ec3c998aadb35255ce2f60bba2940b0)
1import http.server
2import os
3import subprocess
4import sys
5import threading
6
7
8class TrivialHandler(http.server.BaseHTTPRequestHandler):
9    def do_GET(self):
10        self.send_response(501)
11
12    def log_request(self, *args, **kwargs):
13        print(self.requestline)
14        print(self.headers)
15
16
17httpd = http.server.HTTPServer(("", 0), TrivialHandler)
18port = httpd.socket.getsockname()[1]
19
20try:
21    t = threading.Thread(target=httpd.serve_forever).start()
22    os.environ["DEBUGINFOD_URLS"] = f"http://localhost:{port}"
23    subprocess.run(sys.argv[1:], capture_output=True)
24finally:
25    httpd.shutdown()
26