Skip to main content

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

AttributeTypeDescription
protocol_versionstring = HTTP/1.1The 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

TypeDescription
stringThe 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

NameTypeDescription
formatstringA printf-style format string used to structure the log entry.
*argstupleVariable arguments containing request details, typically including the HTTP method and status code.

Returns

TypeDescription
null

get_environ()

@classmethod
def get_environ() - > dict

Generates the WSGI environment dictionary after stripping headers containing underscores to prevent header-spoofing attacks.

Returns

TypeDescription
dictA 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

TypeDescription
null

handle_one_request()

@classmethod
def handle_one_request() - > null

Copy of WSGIRequestHandler.handle() but with different ServerHandler

Returns

TypeDescription
null