This module implements a simple HTTP server (based on
BaseHTTPServer) that serves WSGI applications. Each server
instance serves a single WSGI application on a given host and port. If
you want to serve multiple applications on a single host and port, you
should create a WSGI application that parses PATH_INFO
to select
which application to invoke for each request. (E.g., using the
shift_path_info() function from wsgiref.util.)
host, port, app [, server_class=WSGIServer [, handler_class=WSGIRequestHandler]]) |
Example usage:
from wsgiref.simple_server import make_server, demo_app httpd = make_server('', 8000, demo_app) print "Serving HTTP on port 8000..." # Respond to requests until process is killed httpd.serve_forever() # Alternative: serve one request, then exit ##httpd.handle_request()
environ, start_response) |
server_address, RequestHandlerClass) |
(host,port)
tuple, and RequestHandlerClass should be
the subclass of BaseHTTPServer.BaseHTTPRequestHandler that will
be used to process requests.
You do not normally need to call this constructor, as the make_server() function can handle all the details for you.
WSGIServer is a subclass of BaseHTTPServer.HTTPServer, so all of its methods (such as serve_forever() and handle_request()) are available. WSGIServer also provides these WSGI-specific methods:
application) |
) |
Normally, however, you do not need to use these additional methods, as set_app() is normally called by make_server(), and the get_app() exists mainly for the benefit of request handler instances.
request, client_address, server) |
(host,port)
tuple), and
server (WSGIServer instance).
You do not need to create instances of this class directly; they are automatically created as needed by WSGIServer objects. You can, however, subclass this class and supply it as a handler_class to the make_server() function. Some possibly relevant methods for overriding in subclasses:
) |
) |
wsgi.errors
stream.
The default implementation just returns sys.stderr
.
) |
See About this document... for information on suggesting changes.