From 1d08e2332863986ff531683adf10aac4b69613cb Mon Sep 17 00:00:00 2001 From: "Bala.FA" Date: Fri, 8 Jan 2021 16:01:41 +0530 Subject: [PATCH] Enhance HTTP trace --- Makefile | 2 +- minio/api.py | 19 +++++++++++++++---- minio/helpers.py | 2 +- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 05cebf910..3bfdf07f8 100644 --- a/Makefile +++ b/Makefile @@ -20,4 +20,4 @@ tests: check @echo "Running unit tests" @nosetests @echo "Running functional tests" - @(env bash run_functional_tests.sh) + @env bash run_functional_tests.sh diff --git a/minio/api.py b/minio/api.py index cc3a10bd3..07445d81a 100644 --- a/minio/api.py +++ b/minio/api.py @@ -221,11 +221,10 @@ def _url_open( # pylint: disable=too-many-branches headers=None, query_params=None, preload_content=True, + no_body_trace=False, ): """Execute HTTP request.""" creds = self._provider.retrieve() if self._provider else None - trace_body = isinstance(body, str) - body = body.encode() if trace_body else body url = self._base_url.build( method, region, @@ -259,8 +258,12 @@ def _url_open( # pylint: disable=too-many-branches headers_to_strings(headers, titled_key=True), ) self._trace_stream.write("\n") - if trace_body: - self._trace_stream.write(body.decode()) + if not no_body_trace and body is not None: + self._trace_stream.write("\n") + self._trace_stream.write( + body.decode() if isinstance(body, bytes) else str(body), + ) + self._trace_stream.write("\n") self._trace_stream.write("\n") http_headers = HTTPHeaderDict() @@ -287,6 +290,10 @@ def _url_open( # pylint: disable=too-many-branches if response.status in [200, 204, 206]: if self._trace_stream: + if preload_content: + self._trace_stream.write("\n") + self._trace_stream.write(response.data.decode()) + self._trace_stream.write("\n") self._trace_stream.write("----------END-HTTP----------\n") return response @@ -393,6 +400,7 @@ def _execute( headers=None, query_params=None, preload_content=True, + no_body_trace=False, ): """Execute HTTP request.""" region = self._get_region(bucket_name, None) @@ -407,6 +415,7 @@ def _execute( headers=headers, query_params=query_params, preload_content=preload_content, + no_body_trace=no_body_trace, ) except S3Error as exc: if exc.code != "RetryHead": @@ -423,6 +432,7 @@ def _execute( headers=headers, query_params=query_params, preload_content=preload_content, + no_body_trace=no_body_trace, ) except S3Error as exc: if exc.code != "RetryHead": @@ -1608,6 +1618,7 @@ def _put_object(self, bucket_name, object_name, data, headers, body=data, headers=headers, query_params=query_params, + no_body_trace=True, ) return ObjectWriteResult( bucket_name, diff --git a/minio/helpers.py b/minio/helpers.py index 509eb2a87..c7796a9ec 100644 --- a/minio/helpers.py +++ b/minio/helpers.py @@ -81,7 +81,7 @@ def headers_to_strings(headers, titled_key=False): re.sub( r"Signature=([0-9a-f]+)", "Signature=*REDACTED*", - value, + value if isinstance(value, str) else str(value), ), ) if titled_key else value, ) for key, value in headers.items()