我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用werkzeug._internal._get_environ()。
def make_conditional(self, request_or_environ): """Make the response conditional to the request. This method works best if an etag was defined for the response already. The `add_etag` method can be used to do that. If called without etag just the date header is set. This does nothing if the request method in the request or environ is anything but GET or HEAD. It does not remove the body of the response because that's something the :meth:`__call__` function does for us automatically. Returns self so that you can do ``return resp.make_conditional(req)`` but modifies the object in-place. :param request_or_environ: a request object or WSGI environment to be used to make the response conditional against. """ environ = _get_environ(request_or_environ) if environ['REQUEST_METHOD'] in ('GET', 'HEAD'): # if the date is not in the headers, add it now. We however # will not override an already existing header. Unfortunately # this header will be overriden by many WSGI servers including # wsgiref. if 'date' not in self.headers: self.headers['Date'] = http_date() if self.automatically_set_content_length and 'content-length' not in self.headers: length = self.calculate_content_length() if length is not None: self.headers['Content-Length'] = length if not is_resource_modified(environ, self.headers.get('etag'), None, self.headers.get('last-modified')): self.status_code = 304 return self
def get_response(self, environ=None): """Get a response object. If one was passed to the exception it's returned directly. :param environ: the optional environ for the request. This can be used to modify the response depending on how the request looked like. :return: a :class:`Response` object or a subclass thereof. """ if self.response is not None: return self.response if environ is not None: environ = _get_environ(environ) headers = self.get_headers(environ) return Response(self.get_body(environ), self.code, headers)
def make_conditional(self, request_or_environ): """Make the response conditional to the request. This method works best if an etag was defined for the response already. The `add_etag` method can be used to do that. If called without etag just the date header is set. This does nothing if the request method in the request or environ is anything but GET or HEAD. It does not remove the body of the response because that's something the :meth:`__call__` function does for us automatically. Returns self so that you can do ``return resp.make_conditional(req)`` but modifies the object in-place. :param request_or_environ: a request object or WSGI environment to be used to make the response conditional against. """ environ = _get_environ(request_or_environ) if environ['REQUEST_METHOD'] in ('GET', 'HEAD'): # if the date is not in the headers, add it now. We however # will not override an already existing header. Unfortunately # this header will be overriden by many WSGI servers including # wsgiref. if 'date' not in self.headers: self.headers['Date'] = http_date() if 'content-length' not in self.headers: length = self.calculate_content_length() if length is not None: self.headers['Content-Length'] = length if not is_resource_modified(environ, self.headers.get('etag'), None, self.headers.get('last-modified')): self.status_code = 304 return self