|
|
|
@ -86,7 +86,7 @@ class HttpClient(object):
|
|
|
|
|
stdout, _ = run_command(self.args, cmd, capture=True, always=self.always, cmd_verbosity=2)
|
|
|
|
|
|
|
|
|
|
if self.args.explain and not self.always:
|
|
|
|
|
return HttpResponse(200, '')
|
|
|
|
|
return HttpResponse(method, url, 200, '')
|
|
|
|
|
|
|
|
|
|
header, body = stdout.split('\r\n\r\n', 1)
|
|
|
|
|
|
|
|
|
@ -95,16 +95,20 @@ class HttpClient(object):
|
|
|
|
|
http_response = first_line.split(' ')
|
|
|
|
|
status_code = int(http_response[1])
|
|
|
|
|
|
|
|
|
|
return HttpResponse(status_code, body)
|
|
|
|
|
return HttpResponse(method, url, status_code, body)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class HttpResponse(object):
|
|
|
|
|
"""HTTP response from curl."""
|
|
|
|
|
def __init__(self, status_code, response):
|
|
|
|
|
def __init__(self, method, url, status_code, response):
|
|
|
|
|
"""
|
|
|
|
|
:type method: str
|
|
|
|
|
:type url: str
|
|
|
|
|
:type status_code: int
|
|
|
|
|
:type response: str
|
|
|
|
|
"""
|
|
|
|
|
self.method = method
|
|
|
|
|
self.url = url
|
|
|
|
|
self.status_code = status_code
|
|
|
|
|
self.response = response
|
|
|
|
|
|
|
|
|
@ -115,7 +119,7 @@ class HttpResponse(object):
|
|
|
|
|
try:
|
|
|
|
|
return json.loads(self.response)
|
|
|
|
|
except ValueError:
|
|
|
|
|
raise HttpError(self.status_code, 'Cannot parse response as JSON:\n%s' % self.response)
|
|
|
|
|
raise HttpError(self.status_code, 'Cannot parse response to %s %s as JSON:\n%s' % (self.method, self.url, self.response))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class HttpError(ApplicationError):
|
|
|
|
|