Skip to content

Commit

Permalink
Skip empty content length and type in environ headers
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Dec 30, 2017
1 parent 0c5cad5 commit 625362a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions tests/test_datastructures.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,23 @@ def test_basic_interface(self):
assert not self.storage_class({'wsgi.version': (1, 0)})
assert len(self.storage_class({'wsgi.version': (1, 0)})) == 0

def test_skip_empty_special_vars(self):
env = {
'HTTP_X_FOO': '42',
'CONTENT_TYPE': '',
'CONTENT_LENGTH': '',
}
headers = self.storage_class(env)
assert dict(headers) == {'X-Foo': '42'}

env = {
'HTTP_X_FOO': '42',
'CONTENT_TYPE': '',
'CONTENT_LENGTH': '0',
}
headers = self.storage_class(env)
assert dict(headers) == {'X-Foo': '42', 'Content-Length': '0'}

def test_return_type_is_unicode(self):
# environ contains native strings; we return unicode
headers = self.storage_class({
Expand Down
2 changes: 1 addition & 1 deletion werkzeug/datastructures.py
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,7 @@ def __iter__(self):
('HTTP_CONTENT_TYPE', 'HTTP_CONTENT_LENGTH'):
yield (key[5:].replace('_', '-').title(),
_unicodify_header_value(value))
elif key in ('CONTENT_TYPE', 'CONTENT_LENGTH'):
elif key in ('CONTENT_TYPE', 'CONTENT_LENGTH') and value:
yield (key.replace('_', '-').title(),
_unicodify_header_value(value))

Expand Down

0 comments on commit 625362a

Please sign in to comment.