xref: /llvm-project/llvm/test/tools/llvm-debuginfod-find/Inputs/capture_req.py (revision b71edfaa4ec3c998aadb35255ce2f60bba2940b0)
132a02a9cSDaniel Thornburghimport http.server
232a02a9cSDaniel Thornburghimport os
332a02a9cSDaniel Thornburghimport subprocess
432a02a9cSDaniel Thornburghimport sys
532a02a9cSDaniel Thornburghimport threading
632a02a9cSDaniel Thornburgh
7*b71edfaaSTobias Hieta
832a02a9cSDaniel Thornburghclass TrivialHandler(http.server.BaseHTTPRequestHandler):
932a02a9cSDaniel Thornburgh    def do_GET(self):
1032a02a9cSDaniel Thornburgh        self.send_response(501)
1132a02a9cSDaniel Thornburgh
1232a02a9cSDaniel Thornburgh    def log_request(self, *args, **kwargs):
1332a02a9cSDaniel Thornburgh        print(self.requestline)
1432a02a9cSDaniel Thornburgh        print(self.headers)
1532a02a9cSDaniel Thornburgh
16*b71edfaaSTobias Hieta
17*b71edfaaSTobias Hietahttpd = http.server.HTTPServer(("", 0), TrivialHandler)
1832a02a9cSDaniel Thornburghport = httpd.socket.getsockname()[1]
1932a02a9cSDaniel Thornburgh
2032a02a9cSDaniel Thornburghtry:
2132a02a9cSDaniel Thornburgh    t = threading.Thread(target=httpd.serve_forever).start()
22*b71edfaaSTobias Hieta    os.environ["DEBUGINFOD_URLS"] = f"http://localhost:{port}"
2332a02a9cSDaniel Thornburgh    subprocess.run(sys.argv[1:], capture_output=True)
2432a02a9cSDaniel Thornburghfinally:
2532a02a9cSDaniel Thornburgh    httpd.shutdown()
26