WSGIRequestHandler
This class handles individual HTTP requests for a WSGI-compliant development server by managing request parsing and environment construction. It implements security measures such as stripping headers with underscores to prevent spoofing and provides specialized logging for common configuration errors like HTTPS access on an HTTP-only server. The class also optimizes performance by bypassing reverse DNS lookups for client addresses.
Attributes
| Attribute | Type | Description |
|---|---|---|
| protocol_version | string = HTTP/1.1 | The HTTP protocol version used by the server for responses and to determine connection persistence capabilities. |
Constructor
Signature
def WSGIRequestHandler()
Methods
address_string()
@classmethod
def address_string() - > string
Returns the client's IP address without performing a reverse DNS lookup to avoid latency.
Returns
| Type | Description |
|---|---|
string | The raw IP address of the client making the request. |
log_message()
@classmethod
def log_message(
format: string,
*args: tuple
) - > null
Logs an incoming HTTP request and its status code, including a specific warning if an HTTPS handshake is attempted on this HTTP-only server.
Parameters
| Name | Type | Description |
|---|---|---|
| format | string | A printf-style format string used to structure the log entry. |
| *args | tuple | Variable arguments containing request details, typically including the HTTP method and status code. |
Returns
| Type | Description |
|---|---|
null |
get_environ()
@classmethod
def get_environ() - > dict
Generates the WSGI environment dictionary after stripping headers containing underscores to prevent header-spoofing attacks.
Returns
| Type | Description |
|---|---|
dict | A dictionary containing CGI-style environment variables for the WSGI application. |
handle()
@classmethod
def handle() - > null
Processes incoming requests on the connection, supporting persistent connections by looping until the connection is marked for closure.
Returns
| Type | Description |
|---|---|
null |
handle_one_request()
@classmethod
def handle_one_request() - > null
Copy of WSGIRequestHandler.handle() but with different ServerHandler
Returns
| Type | Description |
|---|---|
null |