Skip to content

Instantly share code, notes, and snippets.

@smerritt
Created August 22, 2016 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smerritt/ca5a6701d46c55b43059e4d0e302c2f9 to your computer and use it in GitHub Desktop.
Save smerritt/ca5a6701d46c55b43059e4d0e302c2f9 to your computer and use it in GitHub Desktop.
diff --git a/swift/common/middleware/slo.py b/swift/common/middleware/slo.py
index d376d3b..2a2b341 100644
--- a/swift/common/middleware/slo.py
+++ b/swift/common/middleware/slo.py
@@ -862,8 +862,8 @@ class StaticLargeObject(object):
if obj_path != last_obj_path:
last_obj_path = obj_path
sub_req = make_subrequest(
- req.environ, path=obj_path + '?', # kill the query string
- method='HEAD',
+ req.environ, path=obj_path,
+ query_string='', method='HEAD',
headers={'x-auth-token': req.headers.get('x-auth-token')},
agent='%(orig)s SLO MultipartPUT', swift_source='SLO')
head_seg_resp = sub_req.get_response(self)
diff --git a/swift/common/request_helpers.py b/swift/common/request_helpers.py
index 308f15d..475ad27 100644
--- a/swift/common/request_helpers.py
+++ b/swift/common/request_helpers.py
@@ -363,9 +363,9 @@ class SegmentedIterable(object):
# segment is a plain old object, not some flavor of large
# object; therefore, its etag is its MD5sum and hence we can
# check it.
- path = seg_path + '?multipart-manifest=get'
seg_req = make_subrequest(
- self.req.environ, path=path, method='GET',
+ self.req.environ, path=seg_path, method='GET',
+ query_string="multipart-manifest=get",
headers={'x-auth-token': self.req.headers.get(
'x-auth-token')},
agent=('%(orig)s ' + self.ua_suffix),
diff --git a/swift/common/wsgi.py b/swift/common/wsgi.py
index 88e61f2..d1901ce 100644
--- a/swift/common/wsgi.py
+++ b/swift/common/wsgi.py
@@ -1138,7 +1138,8 @@ def make_env(env, method=None, path=None, agent='Swift', query_string=None,
def make_subrequest(env, method=None, path=None, body=None, headers=None,
- agent='Swift', swift_source=None, make_env=make_env):
+ agent='Swift', swift_source=None, make_env=make_env,
+ query_string=None):
"""
Makes a new swob.Request based on the current env but with the
parameters specified.
@@ -1146,11 +1147,10 @@ def make_subrequest(env, method=None, path=None, body=None, headers=None,
:param env: The WSGI environment to base the new request on.
:param method: HTTP method of new request; default is from
the original env.
- :param path: HTTP path of new request; default is from the
- original env. path should be compatible with what you
- would send to Request.blank. path should be quoted and it
- can include a query string. for example:
- '/a%20space?unicode_str%E8%AA%9E=y%20es'
+ :param path: HTTP path of new request; default is from the original env.
+ path should be compatible with what you would send to
+ Request.blank. path should be quoted, but it must not
+ include a query string.
:param body: HTTP body of new request; empty by default.
:param headers: Extra HTTP headers of new request; None by
default.
@@ -1164,12 +1164,11 @@ def make_subrequest(env, method=None, path=None, body=None, headers=None,
middleware. Will be logged in proxy logs.
:param make_env: make_subrequest calls this make_env to help build the
swob.Request.
+ :param query_string: HTTP query string of new request; default is from
+ the original env.
:returns: Fresh swob.Request object.
"""
- query_string = None
path = path or ''
- if path and '?' in path:
- path, query_string = path.split('?', 1)
newenv = make_env(env, method, path=unquote(path), agent=agent,
query_string=query_string, swift_source=swift_source)
if not headers:
@@ -1193,8 +1192,10 @@ def make_pre_authed_env(env, method=None, path=None, agent='Swift',
def make_pre_authed_request(env, method=None, path=None, body=None,
- headers=None, agent='Swift', swift_source=None):
+ headers=None, agent='Swift', swift_source=None,
+ query_string=None):
"""Same as :py:func:`make_subrequest` but with preauthorization."""
return make_subrequest(
- env, method=method, path=path, body=body, headers=headers, agent=agent,
- swift_source=swift_source, make_env=make_pre_authed_env)
+ env, method=method, path=path, query_string=query_string,
+ body=body, headers=headers, agent=agent, swift_source=swift_source,
+ make_env=make_pre_authed_env)
diff --git a/test/unit/common/test_wsgi.py b/test/unit/common/test_wsgi.py
index cc33833..46d112a 100644
--- a/test/unit/common/test_wsgi.py
+++ b/test/unit/common/test_wsgi.py
@@ -612,10 +612,12 @@ class TestWSGI(unittest.TestCase):
{'QUERY_STRING': 'original'}, 'GET', 'path')
self.assertEqual(r.query_string, 'original')
r = wsgi.make_pre_authed_request(
- {'QUERY_STRING': 'original'}, 'GET', 'path?replacement')
+ {'QUERY_STRING': 'original'}, 'GET', 'path',
+ query_string='replacement')
self.assertEqual(r.query_string, 'replacement')
r = wsgi.make_pre_authed_request(
- {'QUERY_STRING': 'original'}, 'GET', 'path?')
+ {'QUERY_STRING': 'original'}, 'GET', 'path',
+ query_string='')
self.assertEqual(r.query_string, '')
def test_pre_auth_req_with_body(self):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment