From: Michael Tremer Date: Fri, 31 Dec 2021 10:37:20 +0000 (+0000) Subject: zeiterfassung: Log request/response bodies and allow empty responses X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f38c875a05eeab953ac234e1042412eba1a0e2db;p=ipfire.org.git zeiterfassung: Log request/response bodies and allow empty responses Signed-off-by: Michael Tremer --- diff --git a/src/backend/zeiterfassung.py b/src/backend/zeiterfassung.py index c999a0ca..c156a0a3 100644 --- a/src/backend/zeiterfassung.py +++ b/src/backend/zeiterfassung.py @@ -60,6 +60,8 @@ class ZeiterfassungClient(Object): 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) @@ -72,15 +74,21 @@ class ZeiterfassungClient(Object): # 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