$ python3 -m http.server --help usage: server.py [-h] [--cgi] [--bind ADDRESS] [--directory DIRECTORY] [port] positional arguments: port Specify alternate port [default: 8000] optional arguments: -h, --help show this help message and exit --cgi Run as CGI Server --bind ADDRESS, -b ADDRESS Specify alternate bind address [default: all interfaces] --directory DIRECTORY, -d DIRECTORY Specify alternative directory [default:current directory]
SharedArrayBuffer
object, the two HTTP response headers Cross-Origin-Opener-Policy
and Cross-Origin-Embedder-Policy
must be set to same-origin
and require-corp
. <script> if (typeof(SharedArrayBuffer) === 'undefined') { alert('SharedArrayBuffer is not supported'); } else { alert('SharedArrayBuffer IS supported'); } </script>
SharedArrayBuffer
: from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer class serveWithHeaders(SimpleHTTPRequestHandler): def end_headers(self): self.addHeaders() SimpleHTTPRequestHandler.end_headers(self) def addHeaders(self): self.send_header('Cross-Origin-Opener-Policy', 'same-origin' ) self.send_header('Cross-Origin-Embedder-Policy', 'require-corp') httpd = ThreadingHTTPServer( ('', 8000), serveWithHeaders) httpd.serve_forever()
log_message(format, ...)
logs a message to sys.stderr
. This method is typically overwritten to customize logging. http.server
implements only basic security checks and is therefore not production ready. BaseServer
takes server_address
and a
RequestHandlerClass
(of which an object is intantiated for each request. This class should/must implement handle()
. I believe it must inherit from socketserver.BaseRequestHandler
) TCPServer
additionally takes the bind_and_activate
http.HTTPServer
and http.ThreadingHTTPServer
do not have an explicit constructor. BaseRequestHandler
is the base class for objects that handle requests. BaseServer.finish_request
. BaseServer.serve_forever()
handles one request at a time until shutdown. BaseServer._handle_request_noblock()
self.get_request()
(which returns request
(a socket
object) and client_address
)
self.process_request()
and passes request
and client_address
to this method. BaseServer.process_request()
calls self.finish_request()
and
self.shutdown_request()
BaseServer.finish_request()
RequestHandlerClass
that was passed to the the constructor of HTTPServer
StreamRequestHandler
does not override handle()
. class BaseHTTPRequestHandler
StreamRequestHandler
(which in turn derives from BaseRequestHandler
BaseHTTPRequestHandler.handle_one_request()
(which normally does not need to be overridden) handles one HTTP request. GET /index.html HTTP/1.0
)
self.parse_request()
do_XYZ
(where XYZ
is the request type), for example do_GET
. BaseHTTPRequestHandler.parse_request()
request_line
request_version
command
and path
http.client.parse_headers
and sets headers
TCPServer
BaseServer
) constructor
socket
with a socket.socket
object. TCPServer.get_request()
calls self.socket.accept()
which returns request
(a socket
object) and client_address
. SimpleHTTPServer
merged into http.server
in Python 3?