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

Handle Content-Type headers that contain an encoding #87

Merged
merged 3 commits into from
Sep 15, 2021

Conversation

mthadley
Copy link
Contributor

The Content-Type header is frequently sent like application/json, but it can also contain extra "subtypes" like ; charset=utf8. This leads to an issue with our response handling, as it compares the entire header value (like application/json; charset=urf8) against application/json to determine if the response was JSON.

These changes make that check less exact, and instead we only look to see if the header contains application/json, and then attempt to deserialize JSON.

@mthadley mthadley requested a review from a team as a code owner September 15, 2021 20:16
@@ -11,7 +11,7 @@ def __init__(self, response_dict, status_code, headers=None):
self.headers = {} if headers is None else headers

if "content-type" not in self.headers:
self.headers["content-type"] = "application/json"
self.headers["content-type"] = "application/json; charset=utf-8"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we leave this as-is and instead add two tests that set the Content-Type to application/json and application/json; charset=utf-8 to ensure that both parse the JSON response as expected?

@mthadley mthadley merged commit 17051fb into master Sep 15, 2021
@mthadley mthadley deleted the handle-content-type-with-encoding branch September 15, 2021 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants