Search notes:

Python standard library: http.server

$ 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]

Adding headers to HTTP response

In order to use the 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.
If these header are not set or set to a different value, the following simple HTML page alerts the user that SharedArrayBuffer is not supported:
<script>
   if (typeof(SharedArrayBuffer) === 'undefined') {
      alert('SharedArrayBuffer is not supported');
   }
   else {
      alert('SharedArrayBuffer IS supported');
   }
</script>
The following script sets the two required headers so that the browser does support 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()
See also Python Webserver for CORS compatible HTTP requests

BaseHTTPRequestHandler

Interesting functions and properties

Not production ready

As per the documentation, http.server implements only basic security checks and is therefore not production ready.
Some possible problems are addressed in this Stack Exchange/Information Security question.

TODO

Is Python 2 SimpleHTTPServer merged into http.server in Python 3?

See also

Webservers
standard library (especially http.client)

Index