duck.http.core.wsgiΒΆ
This module provides the WSGI (Web Server Gateway Interface) for the Duck HTTP server.
WSGI is a specification that describes how a web server communicates with web applications. This module will define the WSGI callable that the server will use to serve requests.
Module ContentsΒΆ
ClassesΒΆ
Web Server Gateway Interface for the Duck HTTP server |
APIΒΆ
- class duck.http.core.wsgi.WSGI(settings: Dict[str, Any])ΒΆ
Web Server Gateway Interface for the Duck HTTP server
Notes:
The WSGI callable is the entry point for the server to handle requests.
The WSGI callable will be called for each incoming request.
The WSGI callable will handle the request and send the response to the client.
The WSGI callable will be called with the following arguments: - application: The Duck application instance. - client_socket: The client xsocket object. - client_address: The client address tuple. - request_data: The raw request data from the client.
The WSGI is also responsible for sending request to remote servers like Django for processing.
Implement methods get_request, start_response and call to create your custom WSGI callable.
Initialization
- __call__(application, client_socket: socket.socket, client_address: Tuple[str, int], request_data: duck.http.request_data.RequestData) Optional[duck.http.request.HttpRequest]ΒΆ
WSGI Application callable for handling requests
β¦ admonition:: Notes
This method is wrapped by a decorator (
if_error_log_then_raise), which handle any errors raised within this method.
- Parameters:
application β The Duck application instance.
client_socket β The client socket object.
client_address β The client address tuple.
request_data β The request data object
- Returns:
The handled request object.
- Return type:
HttpRequest
- apply_middlewares_to_response(response, request)ΒΆ
Apply middlewares to the final response starting from the failed middleware or last middleware in list to the first middlewares. Its just like reversing middleware list and iterating through each and every one of them.
- django_apply_middlewares_to_response(response: duck.http.core.proxyhandler.HttpProxyResponse, request)ΒΆ
Applies middlewares to the final http proxy response.
- finalize_response(response, request: Optional[duck.http.request.HttpRequest] = None) NoneΒΆ
Finalizes response by adding final touches and sending response to client.
- static get_request(client_socket: duck.utils.xsocket.xsocket, client_address: Tuple[str, int], request_data: duck.http.request_data.RequestData) duck.http.request.HttpRequestΒΆ
Construct a Request object from the data received from the client
- Parameters:
client_socket β The client xsocket object.
client_address β The client address tuple.
request_data β The request data object
- Returns:
The request object
- Return type:
HttpRequest
- get_response(request: duck.http.request.HttpRequest) duck.http.response.HttpResponseΒΆ
Returns the full response for a request, with all middlewares and other configurations applied.
- Returns:
The corresponding HTTP response.
- Return type:
- Raises:
ExpectingNoResponse β Raised if we are never going to get a response e.g. when we reach a WebSocketView. This handles everything on its own and it will never return a response.
- produce_final_response_failsafe(request: duck.http.request.HttpRequest, response_producer_callable: Callable, processor: Optional[RequestProcessor] = None) duck.http.response.HttpResponseΒΆ
Tries to produce a response a response using the given callable. It handles all errors and produces final response nomatter what.
This returns the full response for a request, with all middlewares and other configurations applied.
- Parameters:
request β Target HTTP request.
response_producer_callable β The callable for producing HTTP response.
processor β Request processor for the request.
- Returns:
The corresponding HTTP response.
- Return type:
- Raises:
ExpectingNoResponse β Raised if we are never going to get a response e.g. when we reach a WebSocketView. This handles everything on its own and it will never return a response.
- send_response(response, client_socket: duck.utils.xsocket.xsocket, request: Optional[duck.http.request.HttpRequest] = None, disable_logging: bool = False)ΒΆ
Sends response to client.
- start_response(request: duck.http.request.HttpRequest, response: Optional[duck.http.response.HttpResponse] = None)ΒΆ
Start the response to the client. This method should be called for handling and sending the response to client.
- Parameters:
request β The request object.
response β An optional response you want to send or the response will just be resolved by normal means.