tornado.httpserver — Non-blocking HTTP server

A non-blocking, single-threaded HTTP server.



HTTP Server

class tornado.httpserver.HTTPServer(request_callback: Union[httputil.HTTPServerConnectionDelegate, Callable[[httputil.HTTPServerRequest], None]], no_keep_alive: bool = False, xheaders: bool = False, ssl_options: Union[Dict[str, Any], ssl.SSLContext] = None, protocol: str = None, decompress_request: bool = False, chunk_size: int = None, max_header_size: int = None, idle_connection_timeout: float = None, body_timeout: float = None, max_body_size: int = None, max_buffer_size: int = None, trusted_downstream: List[str] = None)[source]

A non-blocking, single-threaded HTTP server.






ssl_ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
ssl_ctx.load_cert_chain(os.path.join(data_dir, "mydomain.crt"),
                        os.path.join(data_dir, "mydomain.key"))
HTTPServer(application, ssl_options=ssl_ctx)


  1. listen: simple single-process:

    server = HTTPServer(app)


  2. bind/start: simple multi-process:

    server = HTTPServer(app)
    server.start(0)  # Forks multiple sub-processes


  3. add_sockets: advanced multi-process:

    sockets = tornado.netutil.bind_sockets(8888)
    server = HTTPServer(app)





Changed in version 4.5: Added the trusted_downstream argument.

Changed in version 5.0: The io_loop argument has been removed.

The public interface of this class is mostly inherited from TCPServer and is documented under that class.