Skip to content

Commit

Permalink
Merge pull request #1526 from yangineer/adds_charset_to_header
Browse files Browse the repository at this point in the history
Added charset to HTTPException header content-type
  • Loading branch information
davidism authored May 12, 2019
2 parents 58d3496 + a68c1df commit f6b72e8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Unreleased
- Directive keys for the ``Set-Cookie`` response header are not
ignored when parsing the ``Cookie`` request header. This allows
cookies with names such as "expires" and "version". (:issue:`1495`)
- Add ``charset=utf-8`` to an HTTP exception response's
``CONTENT_TYPE`` header. (:pr:`1526`)


Version 0.15.2
Expand Down
2 changes: 1 addition & 1 deletion src/werkzeug/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def get_body(self, environ=None):

def get_headers(self, environ=None):
"""Get a list of headers."""
return [("Content-Type", "text/html")]
return [("Content-Type", "text/html; charset=utf-8")]

def get_response(self, environ=None):
"""Get a response object. If one was passed to the exception
Expand Down
6 changes: 6 additions & 0 deletions tests/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,9 @@ def test_unauthorized_www_authenticate():
exc = exceptions.Unauthorized(www_authenticate=[digest, basic])
h = dict(exc.get_headers({}))
assert h["WWW-Authenticate"] == ", ".join((str(digest), str(basic)))


def test_response_header_content_type_should_contain_charset():
exc = exceptions.HTTPException("An error message")
h = exc.get_response({})
assert h.headers["Content-Type"] == "text/html; charset=utf-8"

0 comments on commit f6b72e8

Please sign in to comment.