Skip to content

Commit

Permalink
Request.mimetype should be always lowercase #670
Browse files Browse the repository at this point in the history
  • Loading branch information
overdosyu authored and untitaker committed Apr 6, 2015
1 parent 49ee278 commit 6a6c274
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
8 changes: 8 additions & 0 deletions tests/test_datastructures.py
Original file line number Diff line number Diff line change
Expand Up @@ -892,3 +892,11 @@ def test_accept_wildcard_specificity(self):
assert accept.best_match(['asterisk', 'times'], default=None) == \
'times'
assert accept.best_match(['asterisk'], default=None) is None


class TestFileStorage(object):
storage_class = datastructures.FileStorage

def test_mimetype_always_lowercase(self):
file_storage = self.storage_class(content_type='APPLICATION/JSON')
assert file_storage.mimetype == 'application/json'
5 changes: 5 additions & 0 deletions tests/test_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,11 @@ def test_common_request_descriptors_mixin():
assert request.content_md5 == '9a3bc6dbc47a70db25b84c6e5867a072'


def test_request_mimetype_always_lowercase():
request = wrappers.Request.from_values(content_type='APPLICATION/JSON')
assert request.mimetype == 'application/json'


def test_shallow_mode():
request = wrappers.Request({'QUERY_STRING': 'foo=bar'}, shallow=True)
assert request.args['foo'] == 'bar'
Expand Down
8 changes: 4 additions & 4 deletions werkzeug/datastructures.py
Original file line number Diff line number Diff line change
Expand Up @@ -2594,15 +2594,15 @@ def content_length(self):

@property
def mimetype(self):
"""Like :attr:`content_type` but without parameters (eg, without
charset, type etc.). For example if the content
type is ``text/html; charset=utf-8`` the mimetype would be
"""Like :attr:`content_type`, but without parameters (eg, without
charset, type etc.) and always lowercase. For example if the content
type is ``text/HTML; charset=utf-8`` the mimetype would be
``'text/html'``.
.. versionadded:: 0.7
"""
self._parse_content_type()
return self._parsed_content_type[0]
return self._parsed_content_type[0].lower()

@property
def mimetype_params(self):
Expand Down
8 changes: 4 additions & 4 deletions werkzeug/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1621,13 +1621,13 @@ def _parse_content_type(self):

@property
def mimetype(self):
"""Like :attr:`content_type` but without parameters (eg, without
charset, type etc.). For example if the content
type is ``text/html; charset=utf-8`` the mimetype would be
"""Like :attr:`content_type`, but without parameters (eg, without
charset, type etc.) and always lowercase. For example if the content
type is ``text/HTML; charset=utf-8`` the mimetype would be
``'text/html'``.
"""
self._parse_content_type()
return self._parsed_content_type[0]
return self._parsed_content_type[0].lower()

@property
def mimetype_params(self):
Expand Down

0 comments on commit 6a6c274

Please sign in to comment.