Skip to content
Myr

Alternative solution for lack of response caching

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Adam Byrtek · committed by Markus Unterwaditzer · parent 539569e · Browse files · 1 file+14 added−8 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+14 added−8 removed

  • other:+14 added−8 removed

1 file+14 added−8 removed

modified:flask/wrappers.py+14 added-8 removed
16 unmodified lines
1718_missing = object()192021def _get_data(req):22 getter = getattr(req, 'get_data', None)23 if getter is not None:24 return getter()25 return req.data262721class JSONMixin(object):22 """Mixin for both request and response classes to provide JSON parsing23 capabilities.24
24 unmodified lines
49 warn(DeprecationWarning('json is deprecated. '50 'Use get_json() instead.'), stacklevel=2)51 return self.get_json()5253 def _get_data_for_json(req, cache):54 getter = getattr(req, 'get_data', None)55 if getter is not None:56 return getter(cache=cache)57 return req.data5859 def get_json(self, force=False, silent=False, cache=True):60 """Parses the incoming JSON request data and returns it. By default61 this function will return ``None`` if the mimetype is not62 :mimetype:`application/json` but this can be overridden by the
19 unmodified lines
82 # that if the response charset was set explicitly then the data had83 # been encoded correctly as well.84 charset = self.mimetype_params.get('charset')85 try:87 data = _get_data(self)86 data = self._get_data_for_json(cache)87 if charset is not None:88 rv = json.loads(data, encoding=charset)89 else:90 rv = json.loads(data)
122 unmodified lines
213 If you want to replace the response object used you can subclass this and214 set :attr:`~flask.Flask.response_class` to your subclass.215 """216 default_mimetype = 'text/html'217218 def _get_data_for_json(req, cache):219 # Ignore the cache flag since response doesn't support it220 getter = getattr(req, 'get_data', None)221 if getter is not None:222 return getter()223 return req.data