http.server.BaseHTTPRequestHandler()
http.server.BaseHTTPRequestHandler() is a Python function in the HTTP Server Module category. Base class for custom HTTP request handlers. The syntax is http.server.BaseHTTPRequestHandler(request, client_address, server). Returns: Handler class. A typical example: class MyHandler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header("Content-type", "text/plain")
self.end_headers()
self.wfile.write(b"Hello!")
server = HTTPServer(("", 8080), MyHandler)
server.serve_forever(). A close sibling is http.server.HTTPServer(), which creates an HTTP server that listens for connections and dispatches to handlers. A close sibling is http.server.SimpleHTTPRequestHandler(), which a simple request handler that serves files from the current directory. More about this category: Simple HTTP server — HTTPServer, BaseHTTPRequestHandler, SimpleHTTPRequestHandler. Related HTTP Server Module entries: http.server.HTTPServer(), http.server.SimpleHTTPRequestHandler(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details. You can try http.server.BaseHTTPRequestHandler() immediately in the Python playground, look up unfamiliar terms in the glossary, or return to the Python Reference homepage.