-
Notifications
You must be signed in to change notification settings - Fork 17
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
Ensure that bytes/str values are decoded to utf-8 #260
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b01b59b
Ensure that bytes/str values are decoded to utf-8
kolanos cbcd707
Fix compat binary_types
kolanos 8318884
Adding ensure_utf8 test
kolanos e031773
Fix ensure_utf8 test for python 2.7
kolanos cfebf56
Fix docstring typo
kolanos 91b6a5c
Ignore characters that can't decode to utf-8
kolanos 456367e
Apply ensure_utf8 to header keys just in case
kolanos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
BotocoreSession = None | ||
|
||
from iopipe.compat import urlparse | ||
from .util import ensure_utf8 | ||
|
||
if Session is not None: | ||
original_session_send = Session.send | ||
|
@@ -67,7 +68,7 @@ def patch_session_send(context, http_filter): | |
return | ||
|
||
def send(self, *args, **kwargs): | ||
id = str(uuid.uuid4()) | ||
id = ensure_utf8(str(uuid.uuid4())) | ||
with context.iopipe.mark(id): | ||
response = original_session_send(self, *args, **kwargs) | ||
trace = context.iopipe.mark.measure(id) | ||
|
@@ -139,36 +140,36 @@ def collect_metrics_for_response(http_response, context, trace, http_filter): | |
request_headers = [] | ||
if hasattr(http_response.request, "headers"): | ||
request_headers = [ | ||
{"key": k, "string": v} | ||
{"key": k, "string": ensure_utf8(v)} | ||
for k, v in http_response.request.headers.items() | ||
if k.lower() in INCLUDE_HEADERS | ||
] | ||
|
||
request = Request( | ||
hash=getattr(parsed_url, "fragment", None), | ||
hash=ensure_utf8(getattr(parsed_url, "fragment", None)), | ||
headers=request_headers, | ||
hostname=getattr(parsed_url, "hostname", None), | ||
method=getattr(http_response.request, "method", None), | ||
path=getattr(parsed_url, "path", None), | ||
hostname=ensure_utf8(getattr(parsed_url, "hostname", None)), | ||
method=ensure_utf8(getattr(http_response.request, "method", None)), | ||
path=ensure_utf8(getattr(parsed_url, "path", None)), | ||
# TODO: Determine if this is redundant | ||
pathname=getattr(parsed_url, "path", None), | ||
port=getattr(parsed_url, "port", None), | ||
protocol=getattr(parsed_url, "scheme", None), | ||
query=getattr(parsed_url, "query", None), | ||
url=getattr(http_response.request, "url", None), | ||
pathname=ensure_utf8(getattr(parsed_url, "path", None)), | ||
port=ensure_utf8(getattr(parsed_url, "port", None)), | ||
protocol=ensure_utf8(getattr(parsed_url, "scheme", None)), | ||
query=ensure_utf8(getattr(parsed_url, "query", None)), | ||
url=ensure_utf8(getattr(http_response.request, "url", None)), | ||
) | ||
|
||
response_headers = [] | ||
if hasattr(http_response, "headers"): | ||
response_headers = [ | ||
{"key": k, "string": v} | ||
{"key": k, "string": ensure_utf8(v)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the response header key also have UTF-8 ensured? |
||
for k, v in http_response.headers.items() | ||
if k.lower() in INCLUDE_HEADERS | ||
] | ||
|
||
response = Response( | ||
headers=response_headers, | ||
statusCode=getattr(http_response, "status_code", None), | ||
statusCode=ensure_utf8(getattr(http_response, "status_code", None)), | ||
statusMessage=None, | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
from iopipe.compat import binary_types | ||
|
||
|
||
def add_timeline_measures(timeline): | ||
entries = timeline.get_entries_by_type("mark") | ||
measures = timeline.get_entries_by_type("measure") | ||
|
@@ -14,3 +17,10 @@ def add_timeline_measures(timeline): | |
measure_name = "measure:%s" % base_name | ||
if end_name in entry_names and measure_name not in measure_names: | ||
timeline.measure(measure_name, name, end_name) | ||
|
||
|
||
def ensure_utf8(v): | ||
"""Ensures that a binary value is dedoced into utf-8""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Decoded* |
||
if isinstance(v, binary_types): | ||
return v.decode("utf-8") | ||
return v |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the key for the headers also have their UTF-8 ensured?