Merge "Fix HEAD request response when request not given to response."
This commit is contained in:
commit
b6d48c62e6
@ -1008,6 +1008,8 @@ class Response(object):
|
|||||||
return self.host_url + self.location
|
return self.host_url + self.location
|
||||||
|
|
||||||
def __call__(self, env, start_response):
|
def __call__(self, env, start_response):
|
||||||
|
if not self.request:
|
||||||
|
self.request = Request(env)
|
||||||
self.environ = env
|
self.environ = env
|
||||||
app_iter = self._response_iter(self.app_iter, self._body)
|
app_iter = self._response_iter(self.app_iter, self._body)
|
||||||
if 'location' in self.headers:
|
if 'location' in self.headers:
|
||||||
|
@ -462,6 +462,24 @@ class TestResponse(unittest.TestCase):
|
|||||||
resp.body = u'\N{SNOWMAN}'
|
resp.body = u'\N{SNOWMAN}'
|
||||||
self.assertEquals(resp.body, u'\N{SNOWMAN}'.encode('utf-8'))
|
self.assertEquals(resp.body, u'\N{SNOWMAN}'.encode('utf-8'))
|
||||||
|
|
||||||
|
def test_call_reifies_request_if_necessary(self):
|
||||||
|
"""
|
||||||
|
The actual bug was a HEAD response coming out with a body because the
|
||||||
|
Request object wasn't passed into the Response object's constructor.
|
||||||
|
The Response object's __call__ method should be able to reify a
|
||||||
|
Request object from the env it gets passed.
|
||||||
|
"""
|
||||||
|
def test_app(environ, start_response):
|
||||||
|
start_response('200 OK', [])
|
||||||
|
return ['hi']
|
||||||
|
req = swift.common.swob.Request.blank('/')
|
||||||
|
req.method = 'HEAD'
|
||||||
|
status, headers, app_iter = req.call_application(test_app)
|
||||||
|
resp = swift.common.swob.Response(status=status, headers=dict(headers),
|
||||||
|
app_iter=app_iter)
|
||||||
|
output_iter = resp(req.environ, lambda *_: None)
|
||||||
|
self.assertEquals(list(output_iter), [''])
|
||||||
|
|
||||||
def test_location_rewrite(self):
|
def test_location_rewrite(self):
|
||||||
def start_response(env, headers):
|
def start_response(env, headers):
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user