Source code for worldline.connect.sdk.log.response_log_message

from body_obfuscator import BodyObfuscator
from header_obfuscator import HeaderObfuscator
from log_message import LogMessage


[docs]class ResponseLogMessage(LogMessage): """ A utility class to build request log messages. """ def __init__(self, request_id, status_code, duration=-1, body_obfuscator=BodyObfuscator.default_body_obfuscator(), header_obfuscator=HeaderObfuscator.default_header_obfuscator()): super(ResponseLogMessage, self).__init__(request_id, body_obfuscator, header_obfuscator) self.__status_code = status_code self.__duration = duration
[docs] def get_duration(self): return self.__duration
[docs] def get_status_code(self): return self.__status_code
[docs] def get_message(self): if self.__duration < 0: return "Incoming response (requestId='" + self.request_id + "'):\n" + \ " status_code: " + str(self.__status_code) + "\n" + \ " headers: " + self.headers + "\n" + \ " content-type: " + self.empty_if_none(self.content_type) + "\n" + \ " body: " + self.empty_if_none(self.body) else: return "Incoming response (requestId='" + self.request_id + "', " + str(self.__duration) + " ms):\n" + \ " status_code: " + str(self.__status_code) + "\n" + \ " headers: " + self.headers + "\n" + \ " content-type: " + self.empty_if_none(self.content_type) + "\n" + \ " body: " + self.empty_if_none(self.body).encode('utf-8', errors='backslashreplace')