logging.debug("Sending request to %s:" % request.url)
for header in sorted(request.headers):
logging.debug(" %s: %s" % (header, request.headers[header]))
+ if request.body:
+ logging.debug("%s" % json.dumps(kwargs, indent=4, sort_keys=True))
# Send the request
response = await self.backend.http_client.fetch(request)
# Fetch the whole body
body = response.body
+ if body:
+ # Decode the JSON response
+ body = json.loads(body)
+
+ # Log what we have received in a human-readable way
+ logging.debug("%s" % json.dumps(body, indent=4, sort_keys=True))
# Fetch the signature
signature = response.headers.get("Hash")
if not signature:
raise RuntimeError("Could not find signature on response")
- expected_signature = self._sign_response(body)
+ expected_signature = self._sign_response(response.body)
if not hmac.compare_digest(expected_signature, signature):
raise RuntimeError("Invalid signature: %s" % signature)
- # Decode the JSON response
- return json.loads(body)
+ # Return the body
+ return body