rizin/test/scripts/http_server.py
Khairul Azhar Kasmiran 43cb43ed18
Add reliable http:// test (#6509)
* Add reliable http:// test
* REUSE.toml: Add `test/www/**` entry
* Use `cwd` instead to work around old http.server in Python 3.6
* Move test to `not-windows-any`
* NetBSD: Add `python3` symbolic link
* Prevent test from running on woodpecker
2026-06-18 07:01:00 +08:00

31 lines
636 B
Python
Executable file

#!/usr/bin/env python3
r"""
This script launches python -m http.server in a subprocess and waits until it's ready to receive
a new connection.
"""
import http.client
import subprocess
def main():
subprocess.run(
"python3 -m http.server 9000 --bind 127.0.0.1 &",
shell=True,
check=True,
cwd="www",
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
while True:
try:
http.client.HTTPConnection("127.0.0.1", 9000, timeout=5).connect()
except ConnectionRefusedError:
continue
break
if __name__ == "__main__":
main()