Update to _response_handler
Account for situations where no Content-Length or Transfer-Encoding headers are present in a response. The length of the response.content could still indicate a response was given. The earlier raise_for_status() should catch bad HTTP responses that return content. Closes-bug: #1766660 Change-Id: I6739e26a039a898982f5cdc96d19d6992ed37737
This commit is contained in:
@@ -505,13 +505,14 @@ class Jenkins(object):
|
|||||||
|
|
||||||
headers = response.headers
|
headers = response.headers
|
||||||
if (headers.get('content-length') is None and
|
if (headers.get('content-length') is None and
|
||||||
headers.get('transfer-encoding') is None):
|
headers.get('transfer-encoding') is None and
|
||||||
|
(response.content is None or len(response.content) <= 0)):
|
||||||
# response body should only exist if one of these is provided
|
# response body should only exist if one of these is provided
|
||||||
raise EmptyResponseException(
|
raise EmptyResponseException(
|
||||||
"Error communicating with server[%s]: "
|
"Error communicating with server[%s]: "
|
||||||
"empty response" % self.server)
|
"empty response" % self.server)
|
||||||
|
|
||||||
# Reponse objects will automatically return unicode encoded
|
# Response objects will automatically return unicode encoded
|
||||||
# when accessing .text property
|
# when accessing .text property
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
@@ -102,5 +102,6 @@ def build_response_mock(status_code, json_body=None, headers=None, **kwargs):
|
|||||||
# for some reason, wraps cannot handle attributes which are dicts
|
# for some reason, wraps cannot handle attributes which are dicts
|
||||||
# and accessed by key
|
# and accessed by key
|
||||||
response.headers = real_response.headers
|
response.headers = real_response.headers
|
||||||
|
response.content = text
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
Reference in New Issue
Block a user