Skip to content

Commit

Permalink
case insensitive header for reading Content-Type header value
Browse files Browse the repository at this point in the history
  • Loading branch information
siddhantgoel committed May 11, 2018
1 parent 6fa2d23 commit 2390e94
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
7 changes: 6 additions & 1 deletion streaming_form_data/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ class ParseFailedException(Exception):


def parse_content_boundary(headers):
content_type = headers.get('Content-Type')
content_type_header = 'Content-Type'

content_type = headers.get(content_type_header) or \
headers.get(content_type_header.lower()) or \
headers.get(content_type_header.upper())

if not content_type:
raise ParseFailedException()

Expand Down
18 changes: 18 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,24 @@ def test_basic_single(self):

self.assertEqual(target.value, b'hello world')

def test_case_insensitive_content_type(self):
content_type_header = 'Content-Type'

for header_key in (content_type_header,
content_type_header.lower(),
content_type_header.upper()):
target = ValueTarget()

encoder = MultipartEncoder(fields={'value': 'hello world'})

parser = StreamingFormDataParser(
headers={header_key: encoder.content_type})
parser.register('value', target)

parser.data_received(encoder.to_string())

self.assertEqual(target.value, b'hello world')

def test_basic_multiple(self):
first = ValueTarget()
second = ValueTarget()
Expand Down

0 comments on commit 2390e94

Please sign in to comment.