Skip to content

Commit

Permalink
Merge pull request #11 from dich1123/feature/STS-1691-Support_charset…
Browse files Browse the repository at this point in the history
…=utf-8_in_Accept

Add charset=utf-8 support in Accept header
  • Loading branch information
JonathanHuot committed Jun 30, 2021
2 parents d696c83 + 7e58524 commit fe4cbca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bottle_oauthlib/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def set_response(bottle_request, bottle_response, status, headers, body, force_j
# request want a json as response
if force_json is True or (
"Accept" in bottle_request.headers and
"application/json" == bottle_request.headers["Accept"]):
"application/json" in bottle_request.headers["Accept"]):
bottle_response["Content-Type"] = "application/json;charset=UTF-8"
bottle_response.body = body
log.debug("Body Bottle response body created as json: %r", bottle_response.body)
Expand Down
10 changes: 10 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,13 @@ def test_resp_body_json_accept_all_encoded_item(self):
)
self.assertIn("application/x-www-form-urlencoded", self.response["Content-Type"])
self.assertEqual(self.response.body, 'foo=bar&bar=http%3A//foo%3Fbar%23fragment')

def test_resp_body_json_accept_json_encoding(self):
self.request.headers["Accept"] = "application/json; charset=utf-8"
oauth2.set_response(
self.request, self.response, 200,
{"Content-Type": "application/json; charset=utf-8"},
'{"foo": "bar", "bar": "foo"}'
)
self.assertIn("application/json", self.response["Content-Type"])
self.assertEqual(self.response.body, '{"foo": "bar", "bar": "foo"}')

0 comments on commit fe4cbca

Please sign in to comment.