More attributes of flask.request in RequestDetails

To simplify the writing of extensions, and to reduce reliance on
importing the flask.request global object, store pertinent attributes
of flask.request in the RequestDetails class.

Change-Id: Idff737155a6110d0520a74e36a5b0c23b5b5d93c
This commit is contained in:
Jeremy Freudberg 2017-09-11 19:47:09 +00:00
parent dfd5fff51d
commit b23bf3cefa
2 changed files with 9 additions and 7 deletions

View File

@ -13,7 +13,6 @@
# under the License.
from mixmatch.extend import base
from mixmatch.session import request as mm_request
from oslo_serialization import jsonutils
@ -35,7 +34,7 @@ class NameRouting(base.Extension):
if self._is_targeted(request.headers):
return
body = jsonutils.loads(mm_request.data)
body = jsonutils.loads(request.body)
if request.service == 'image':
if request.version == 'v1':
name = request.headers.get('X-IMAGE-META-NAME', '')

View File

@ -94,6 +94,10 @@ class RequestDetails(object):
self.token = headers.get('X-AUTH-TOKEN', None)
self.headers = dict(headers)
self.path = orig_path
self.args = dict(request.args)
# NOTE(jfreud): if chunked transfer, body must be accessed through
# utilities found in mixmatch.session
self.body = request.data
class RequestHandler(object):
@ -187,13 +191,13 @@ class RequestHandler(object):
'method': self.details.method,
'url': url,
'headers': headers,
'params': self._prepare_args(request.args)
'params': self._prepare_args(self.details.args)
}
if self.chunked:
resp = self.session.request(data=chunked_reader(),
**request_kwargs)
else:
resp = self.session.request(data=request.data,
resp = self.session.request(data=self.details.body,
stream=self.stream,
**request_kwargs)
LOG.info(format_for_log(title='Request from proxy',
@ -265,7 +269,7 @@ class RequestHandler(object):
self.details.action[0],
self.details.service,
version=self.details.version,
params=dict(request.args),
params=self.details.args,
path=request.base_url,
strip_details=self.strip_details),
200,
@ -304,13 +308,12 @@ class RequestHandler(object):
return headers
@staticmethod
def _prepare_args(user_args):
def _prepare_args(args):
"""Prepare the GET arguments by removing the limit and marker.
This is because the id of the marker will only be present in one of
the service providers.
"""
args = dict(user_args)
if CONF.aggregation:
args.pop('limit', None)
args.pop('marker', None)