bencher.file_server

Serve files from a directory over HTTP with CORS headers (stdlib only).

Classes

_CORSHandler

Static file handler with full CORS support (including preflight).

_ReusableServer

Mix-in class to handle each request in a new thread.

Functions

create_server(directory[, port])

Create an HTTP server serving directory on port.

run_file_server([directory, port])

Start a background HTTP file server (daemon thread).

Module Contents

class bencher.file_server._CORSHandler(*args, directory=None, **kwargs)

Bases: http.server.SimpleHTTPRequestHandler

Static file handler with full CORS support (including preflight).

end_headers()

Send the blank line ending the MIME headers.

do_OPTIONS()
log_message(*_args, **_kwargs)

Log an arbitrary message.

This is used by all other logging functions. Override it if you have specific logging wishes.

The first argument, FORMAT, is a format string for the message to be logged. If the format string contains any % escapes requiring parameters, they should be specified as subsequent arguments (it’s just like printf!).

The client ip and current date/time are prefixed to every message.

Unicode control characters are replaced with escaped hex before writing the output to stderr.

class bencher.file_server._ReusableServer(server_address, RequestHandlerClass, bind_and_activate=True)

Bases: http.server.ThreadingHTTPServer

Mix-in class to handle each request in a new thread.

allow_reuse_address = True
bencher.file_server.create_server(directory, port=8001)

Create an HTTP server serving directory on port.

bencher.file_server.run_file_server(directory=None, port=8001)

Start a background HTTP file server (daemon thread).

If port is already in use the existing server is assumed to be running and the function returns None instead of raising.

Returns the ThreadingHTTPServer so callers can query server.server_address[1] for the actual port (useful when port=0).