The SimpleHTTPRequestHandler class of http server module directly maps the directory structure to HTTP requests. Work like parsing the requests is done by the base class, that is BaseHTTPRequestHandler.
Attributes of SimpleHTTPRequestHandler
The class-level attributes of SimpleHTTPRequestHandler are elaborated below.
It is represented as 'SimpleHTTP/" + __version__', wherein the version part is described at the module level.
This dictionary maps suffixes into MIME types. The mapping used is case-insensitive
and uncluses lower-case keys only. For default system mappings, custom overrides are present.
Methods of SimpleHTTPRequestHandler
This method sends out the headers that it would send for an equivalent GET request. The do_GET method will provide more clarity on the same.
By understanding the request as a path relative to the current working directory, the request is mapped to a local file.
For example, if the request was mapped to a directory, a file named index.html or index.htm is verified in that directory. If the file is located, the contents are returned; otherwise, the list directory() method is used to construct a directory listing os.listdir() is used in this technique.
The next article will help you know how SimpleHTTPRequestHandler can be used to make a simple webserver to serve files that are relative to current directory.
To know more about http.server module and its classes, refer to the following article: