add helper for serving a directory (#31802)

directory http server
old-commit-hash: 358461896c
chrysler-long2
Justin Newberry 1 year ago committed by GitHub
parent 6bf5c62155
commit 52a32bf132
  1. 9
      selfdrive/test/helpers.py

@ -113,3 +113,12 @@ def with_http_server(func, handler=http.server.BaseHTTPRequestHandler, setup=Non
with http_server_context(handler, setup) as (host, port): with http_server_context(handler, setup) as (host, port):
return func(*args, f"http://{host}:{port}", **kwargs) return func(*args, f"http://{host}:{port}", **kwargs)
return inner return inner
def DirectoryHttpServer(directory) -> type[http.server.SimpleHTTPRequestHandler]:
# creates an http server that serves files from directory
class Handler(http.server.SimpleHTTPRequestHandler):
def __init__(self, *args, **kwargs):
super().__init__(*args, directory=str(directory), **kwargs)
return Handler

Loading…
Cancel
Save