Browse Source

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
Jeremy Freudberg 1 year ago
parent
commit
b23bf3cefa
2 changed files with 9 additions and 7 deletions
  1. 1
    2
      mixmatch/extend/name_routing.py
  2. 8
    5
      mixmatch/proxy.py

+ 1
- 2
mixmatch/extend/name_routing.py View File

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

+ 8
- 5
mixmatch/proxy.py View File

@@ -94,6 +94,10 @@ class RequestDetails(object):
94 94
         self.token = headers.get('X-AUTH-TOKEN', None)
95 95
         self.headers = dict(headers)
96 96
         self.path = orig_path
97
+        self.args = dict(request.args)
98
+        # NOTE(jfreud): if chunked transfer, body must be accessed through
99
+        # utilities found in mixmatch.session
100
+        self.body = request.data
97 101
 
98 102
 
99 103
 class RequestHandler(object):
@@ -187,13 +191,13 @@ class RequestHandler(object):
187 191
             'method': self.details.method,
188 192
             'url': url,
189 193
             'headers': headers,
190
-            'params': self._prepare_args(request.args)
194
+            'params': self._prepare_args(self.details.args)
191 195
         }
192 196
         if self.chunked:
193 197
             resp = self.session.request(data=chunked_reader(),
194 198
                                         **request_kwargs)
195 199
         else:
196
-            resp = self.session.request(data=request.data,
200
+            resp = self.session.request(data=self.details.body,
197 201
                                         stream=self.stream,
198 202
                                         **request_kwargs)
199 203
         LOG.info(format_for_log(title='Request from proxy',
@@ -265,7 +269,7 @@ class RequestHandler(object):
265 269
                                    self.details.action[0],
266 270
                                    self.details.service,
267 271
                                    version=self.details.version,
268
-                                   params=dict(request.args),
272
+                                   params=self.details.args,
269 273
                                    path=request.base_url,
270 274
                                    strip_details=self.strip_details),
271 275
                 200,
@@ -304,13 +308,12 @@ class RequestHandler(object):
304 308
         return headers
305 309
 
306 310
     @staticmethod
307
-    def _prepare_args(user_args):
311
+    def _prepare_args(args):
308 312
         """Prepare the GET arguments by removing the limit and marker.
309 313
 
310 314
         This is because the id of the marker will only be present in one of
311 315
         the service providers.
312 316
         """
313
-        args = dict(user_args)
314 317
         if CONF.aggregation:
315 318
             args.pop('limit', None)
316 319
             args.pop('marker', None)

Loading…
Cancel
Save