MCPcopy
hub / github.com/django/django / WSGIRequest

Class WSGIRequest

django/core/handlers/wsgi.py:56–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54
55
56class WSGIRequest(HttpRequest):
57 def __init__(self, environ):
58 script_name = get_script_name(environ)
59 # If PATH_INFO is empty (e.g. accessing the SCRIPT_NAME URL without a
60 # trailing slash), operate as if '/' was requested.
61 path_info = get_path_info(environ) or "/"
62 self.environ = environ
63 self.path_info = path_info
64 # be careful to only replace the first slash in the path because of
65 # http://test/something and http://test//something being different as
66 # stated in RFC 3986.
67 self.path = "%s/%s" % (script_name.rstrip("/"), path_info.replace("/", "", 1))
68 self.META = environ
69 self.META["PATH_INFO"] = path_info
70 self.META["SCRIPT_NAME"] = script_name
71 self.method = environ["REQUEST_METHOD"].upper()
72 # Set content_type, content_params, and encoding.
73 self._set_content_type_params(environ)
74 try:
75 content_length = int(environ.get("CONTENT_LENGTH"))
76 except (ValueError, TypeError):
77 content_length = 0
78 self._stream = LimitedStream(self.environ["wsgi.input"], content_length)
79 self._read_started = False
80 self.resolver_match = None
81
82 def _get_scheme(self):
83 return self.environ.get("wsgi.url_scheme")
84
85 @cached_property
86 def GET(self):
87 # The WSGI spec says 'QUERY_STRING' may be absent.
88 raw_query_string = get_bytes_from_wsgi(self.environ, "QUERY_STRING", "")
89 return QueryDict(raw_query_string, encoding=self._encoding)
90
91 def _get_post(self):
92 if not hasattr(self, "_post"):
93 self._load_post_and_files()
94 return self._post
95
96 def _set_post(self, post):
97 self._post = post
98
99 @cached_property
100 def COOKIES(self):
101 raw_cookie = get_str_from_wsgi(self.environ, "HTTP_COOKIE", "")
102 return parse_cookie(raw_cookie)
103
104 @property
105 def FILES(self):
106 if not hasattr(self, "_files"):
107 self._load_post_and_files()
108 return self._files
109
110 POST = property(_get_post, _set_post)
111
112
113class WSGIHandler(base.BaseHandler):

Callers 15

__call__Method · 0.90
requestMethod · 0.90
test_non_ascii_cookieMethod · 0.90
test_log_messageMethod · 0.90
test_httpsMethod · 0.90
test_wsgirequestMethod · 0.90

Calls

no outgoing calls