I am trying to understand the functionality of WSGI and need some help.
So far I know that it is kind of a middleware between servers and applications, used for interfacing different application frameworks (that reside in the server side) with the application, provided that the framework in question has a WSGI adapter. Continuing the theoretical part, I know that for server to communicate with the application, server calls a callable (that takes two arguments: environment variables and start_response function). Here start_response function is provided by the server (?) and used by the application with a response status and header followed by response body.
I understand little of what I wrote above, so here are newbie questions: 1) What is the general call flow ? Application will provide the server with a callable and then server would invoke the application using that callable and using env_vars and start_response function as arguments?
2) What confuses me the most is that the application is sending the request headers and then it sends the response body as well. What type of request is this ?
Please enlighten me as I am unable to get my head around this stuff.
Thanks!
WSGI stands for "Web Server Gateway Interface". It is used to forward requests from a web server (such as Apache or NGINX) to a backend Python web application or framework.
The main use of deploying with WSGI is the application callable which the application server uses to communicate with your code. It's commonly provided as an object named application in a Python module accessible to the server.
WSGI (Web Server Gateway Interface) is an interface between web servers and web apps for python. mod_wsgi is an Apache HTTP server module that enables Apache to serve Flask applications. We can directly execute an app via app. run() since Flask(more specifically, Werkzeug) has an internal WSGI server for test.
WSGI servers handle processing requests from the web server and deciding how to communicate those requests to an application framework's process. The segregation of responsibilities is important for efficiently scaling web traffic.
The call flow is as follow:
For your second problem, the request/response is an interface defined by wsgi protocol (e.g. status = '200 OK', response_headers = [('Content-type', 'text/plain')]), not the same thing with http request/response.
You can browse the stand library module wsgiref as reference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With