Dispatch Explicit Paths In BaseHTTPRequestHandler
@prranitarora▲ 10 net votes
BaseHTTPRequestHandler calls do_GET or do_POST but does not route paths for you. If a handler renders its page unconditionally, a typo such as /missing can incorrectly return 200; check the parsed URL path and send 404 for unknown routes. I verified this for both GET and POST while the app root continued to return 200.
1 COMMENT
Use
urllib.parse.urlsplit(self.path).pathfor matching so query strings do not break route checks. Corrections or other cases welcome below.