environ是请求信息,但是environ是哪里来的呢,看了werkzeug的源码,只追溯到Request的基类BaseRequest类中 `self.environ = environ` 不明白这个environ是哪里来的!
看werkzeug的文档的例子:
``` python
from werkzeug.wrappers import Request, Response
from werkzeug.serving import run_simple
class Fish(object):
def __init__(self, package_name):
self.package_name = package_name
self.debug = False
def dispatch_request(self, request, environ):
return Response('Hello \n%s!\n%s' % (environ or "World", request))
def run(self, host="127.0.0.1", port=8000, **options):
if 'debug' in options:
self.debug = options.pop('debug')
options.setdefault('use_reloader', self.debug)
options.setdefault('use_debugger', self.debug)
return run_simple(host, port, self, **options)
def wsgi_app(self, environ, start_response):
request = Request(environ)
#start_response('200 OK', [('Content-Type', 'text/html')])
response = self.dispatch_request(request, environ)
return response(environ, start_response)
def __call__(self, environ, start_response):
return self.wsgi_app(environ, start_response)
def create_app(package_name=None):
app = Fish(package_name)
return app
if __name__ == '__main__':
app = Fish(__name__)
app.run(debug=True)
```
浏览器返回:
```
Hello
{'wsgi.multiprocess': False, 'HTTP_COOKIE': 'CNZZDATA1254582975=2053663334-1430877964-%7C1430981140; csrftoken=3Tbk7YLoAjrq92l6SYoQQk0sr7Tb7mtz; session=.eJy9j1trgzAAhf-K5Fl07SYMwYeBWIQZcaQtcS2iMV7iJZ2JOFP877Pb2Nvexp7O0_m-c64gKdpUVFQA-_UKNPkVGbBBdjwosvX6OHIcsOjgmZd1rw30baRC0lwr-KCFF9r7rnMClZQXYZvmNE1GyXnZUoPwzkwJ4WMvhckfzTo_AX3td7TL6JB01PHSVlBwXvT_FqNh_CtvR405rTi_WX_RnHWQ1DmwvzUhIpsYNTN0qyZ09xZk0R1GsIl3kQoRfofMf4jZfo7R0-cMIoYikbyh_Q8CKv8eHr0aopcaI2IFW3-tts2KtcIVi5XHAoY3uPMVRgcW7AIVlLdXywf3RaYZ.CF0JVA.a_wB5LdgWoNgbnjdbA6g_WoCDy0', 'SERVER_SOFTWARE': 'Werkzeug/0.10.4', 'SCRIPT_NAME': '', 'REQUEST_METHOD': 'GET', 'PATH_INFO': '/saas', 'SERVER_PROTOCOL': 'HTTP/1.1', 'QUERY_STRING': '', 'werkzeug.server.shutdown': <function shutdown_server at 0x7f124c56a578>, 'CONTENT_LENGTH': '', 'HTTP_USER_AGENT': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36', 'HTTP_CONNECTION': 'keep-alive', 'SERVER_NAME': '127.0.0.1', 'REMOTE_PORT': 57239, 'wsgi.url_scheme': 'http', 'SERVER_PORT': '8000', 'werkzeug.request': <Request '
http://127.0.0.1:8000/saas' [GET]>, 'wsgi.input': <socket._fileobject object at 0x7f124c589650>, 'HTTP_HOST': '127.0.0.1:8000', 'wsgi.multithread': False, 'HTTP_ACCEPT': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'HTTP_RA_SID': 'B47161C4-20140503-060942-d9d373-241f9a', 'wsgi.version': (1, 0), 'wsgi.run_once': False, 'HTTP_RA_VER': '2.10.4', 'wsgi.errors': <open file '<stderr>', mode 'w' at 0x7f124fa781e0>, 'REMOTE_ADDR': '127.0.0.1', 'HTTP_ACCEPT_LANGUAGE': 'en', 'CONTENT_TYPE': '', 'HTTP_ACCEPT_ENCODING': 'gzip, deflate, sdch'}!
<Request '
http://127.0.0.1:8000/saas' [GET]>
```
这个environ是dict对象,但是这些请求信息是从哪里得到的,并且怎么赋给environ的呢?