Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance HTTP trace #1056

Merged
merged 1 commit into from
Jan 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 15 additions & 4 deletions minio/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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":
Expand All @@ -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":
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion minio/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down