Batch error response reason not being set correctly.
Reviewed in http://codereview.appspot.com/6355092/. Fixes issue #165.
This commit is contained in:
@@ -854,7 +854,7 @@ class BatchHttpRequest(object):
|
|||||||
# Unique ID on which to base the Content-ID headers.
|
# Unique ID on which to base the Content-ID headers.
|
||||||
self._base_id = None
|
self._base_id = None
|
||||||
|
|
||||||
# A map from request id to (headers, content) response pairs
|
# A map from request id to (httplib2.Response, content) response pairs
|
||||||
self._responses = {}
|
self._responses = {}
|
||||||
|
|
||||||
# A map of id(Credentials) that have been refreshed.
|
# A map of id(Credentials) that have been refreshed.
|
||||||
@@ -982,7 +982,7 @@ class BatchHttpRequest(object):
|
|||||||
payload: string, headers and body as a string.
|
payload: string, headers and body as a string.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
A pair (resp, content) like would be returned from httplib2.request.
|
A pair (resp, content), such as would be returned from httplib2.request.
|
||||||
"""
|
"""
|
||||||
# Strip off the status line
|
# Strip off the status line
|
||||||
status_line, payload = payload.split('\n', 1)
|
status_line, payload = payload.split('\n', 1)
|
||||||
@@ -1110,8 +1110,8 @@ class BatchHttpRequest(object):
|
|||||||
|
|
||||||
for part in mime_response.get_payload():
|
for part in mime_response.get_payload():
|
||||||
request_id = self._header_to_id(part['Content-ID'])
|
request_id = self._header_to_id(part['Content-ID'])
|
||||||
headers, content = self._deserialize_response(part.get_payload())
|
response, content = self._deserialize_response(part.get_payload())
|
||||||
self._responses[request_id] = (headers, content)
|
self._responses[request_id] = (response, content)
|
||||||
|
|
||||||
def execute(self, http=None):
|
def execute(self, http=None):
|
||||||
"""Execute all the requests as a single batched HTTP request.
|
"""Execute all the requests as a single batched HTTP request.
|
||||||
@@ -1148,8 +1148,8 @@ class BatchHttpRequest(object):
|
|||||||
redo_order = []
|
redo_order = []
|
||||||
|
|
||||||
for request_id in self._order:
|
for request_id in self._order:
|
||||||
headers, content = self._responses[request_id]
|
resp, content = self._responses[request_id]
|
||||||
if headers['status'] == '401':
|
if resp['status'] == '401':
|
||||||
redo_order.append(request_id)
|
redo_order.append(request_id)
|
||||||
request = self._requests[request_id]
|
request = self._requests[request_id]
|
||||||
self._refresh_and_apply_credentials(request, http)
|
self._refresh_and_apply_credentials(request, http)
|
||||||
@@ -1163,7 +1163,7 @@ class BatchHttpRequest(object):
|
|||||||
# that contains an HttpError?
|
# that contains an HttpError?
|
||||||
|
|
||||||
for request_id in self._order:
|
for request_id in self._order:
|
||||||
headers, content = self._responses[request_id]
|
resp, content = self._responses[request_id]
|
||||||
|
|
||||||
request = self._requests[request_id]
|
request = self._requests[request_id]
|
||||||
callback = self._callbacks[request_id]
|
callback = self._callbacks[request_id]
|
||||||
@@ -1171,8 +1171,7 @@ class BatchHttpRequest(object):
|
|||||||
response = None
|
response = None
|
||||||
exception = None
|
exception = None
|
||||||
try:
|
try:
|
||||||
r = httplib2.Response(headers)
|
response = request.postproc(resp, content)
|
||||||
response = request.postproc(r, content)
|
|
||||||
except HttpError, e:
|
except HttpError, e:
|
||||||
exception = e
|
exception = e
|
||||||
|
|
||||||
|
|||||||
@@ -386,7 +386,7 @@ Content-Type: application/http
|
|||||||
Content-Transfer-Encoding: binary
|
Content-Transfer-Encoding: binary
|
||||||
Content-ID: <randomness+1>
|
Content-ID: <randomness+1>
|
||||||
|
|
||||||
HTTP/1.1 401 Authoration Required
|
HTTP/1.1 401 Authorization Required
|
||||||
Content-Type application/json
|
Content-Type application/json
|
||||||
Content-Length: 14
|
Content-Length: 14
|
||||||
ETag: "etag/pony"\r\n\r\n{"error": {"message":
|
ETag: "etag/pony"\r\n\r\n{"error": {"message":
|
||||||
@@ -650,6 +650,8 @@ class TestBatch(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(None, callbacks.responses['1'])
|
self.assertEqual(None, callbacks.responses['1'])
|
||||||
self.assertEqual(401, callbacks.exceptions['1'].resp.status)
|
self.assertEqual(401, callbacks.exceptions['1'].resp.status)
|
||||||
|
self.assertEqual(
|
||||||
|
'Authorization Required', callbacks.exceptions['1'].resp.reason)
|
||||||
self.assertEqual({u'baz': u'qux'}, callbacks.responses['2'])
|
self.assertEqual({u'baz': u'qux'}, callbacks.responses['2'])
|
||||||
self.assertEqual(None, callbacks.exceptions['2'])
|
self.assertEqual(None, callbacks.exceptions['2'])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user