Response logs now optionally show the query string when logging, defaulting to always show the logs for now however
This commit is contained in:
parent
ab6b8e460b
commit
fb36f70d95
@ -18,6 +18,12 @@ class Response:
|
|||||||
|
|
||||||
self.method = method
|
self.method = method
|
||||||
self.url = url
|
self.url = url
|
||||||
|
self.base_url = self.url[:self.url.find('?')]
|
||||||
|
try:
|
||||||
|
self.query_string = self.url.strip(self.base_url)[1:]
|
||||||
|
except: # do this for empty query strings
|
||||||
|
self.query_string = self.url.strip(self.base_url)
|
||||||
|
|
||||||
self.body = body #typically a string before parsing anything
|
self.body = body #typically a string before parsing anything
|
||||||
self.code = code #u16
|
self.code = code #u16
|
||||||
self.expected = expected #u16
|
self.expected = expected #u16
|
||||||
@ -45,6 +51,8 @@ class Response:
|
|||||||
if (len(s) == 1 or len(s) == 0) is False: print(s, file=self.out)
|
if (len(s) == 1 or len(s) == 0) is False: print(s, file=self.out)
|
||||||
|
|
||||||
def _log_body(self):
|
def _log_body(self):
|
||||||
|
# TODO: refactor this func to be more flexible as its hella useful
|
||||||
|
# for truncating ugly long as hell strings
|
||||||
if self.truncate_long_body:
|
if self.truncate_long_body:
|
||||||
if len(self.body) > 80:
|
if len(self.body) > 80:
|
||||||
msg = self.body
|
msg = self.body
|
||||||
@ -58,10 +66,9 @@ class Response:
|
|||||||
else:
|
else:
|
||||||
self.__write_msg(f'\t{self.body}')
|
self.__write_msg(f'\t{self.body}')
|
||||||
|
|
||||||
def log(self):
|
def log(self, show_query: bool = True):
|
||||||
if self.code != self.expected:
|
if self.code != self.expected:
|
||||||
base_url = self.url[:self.url.find('?')]
|
fail = f'Failed {self.method.upper()} {self.base_url}\t{self.code} expected {self.expected}\n'
|
||||||
fail = f'Failed {self.method.upper()} {base_url}\t{self.code} expected {self.expected}\n'
|
|
||||||
content = f'\tRaw params: {self.raw_params[0]}\n\tParsed Params: {self.raw_params[1]}'
|
content = f'\tRaw params: {self.raw_params[0]}\n\tParsed Params: {self.raw_params[1]}'
|
||||||
if self.color:
|
if self.color:
|
||||||
fail = self._color_failing(fail)
|
fail = self._color_failing(fail)
|
||||||
@ -70,10 +77,14 @@ class Response:
|
|||||||
self.__write_msg(content)
|
self.__write_msg(content)
|
||||||
self._log_body()
|
self._log_body()
|
||||||
else:
|
else:
|
||||||
msg = f'Passing: {self.method} {self.url}'
|
msg = f'Passing: {self.method} {self.base_url}'
|
||||||
if self.color:
|
if self.color:
|
||||||
msg = self._color_passing(msg)
|
msg = self._color_passing(msg)
|
||||||
|
|
||||||
|
# no color on the query like ever(because its typically massive
|
||||||
|
if show_query:
|
||||||
|
msg += f'\n\t{self.query_string[:80]}'
|
||||||
|
|
||||||
self.__write_msg(msg)
|
self.__write_msg(msg)
|
||||||
|
|
||||||
def json(self):
|
def json(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user