case-insensitive check for header fields

This commit is contained in:
Yun Xu 2017-07-10 12:29:47 -07:00
parent 39ea434513
commit 3d75e6ed95
2 changed files with 16 additions and 10 deletions

View File

@ -242,11 +242,11 @@ def parse_multipart_form(body, boundary):
form_header_value, form_parameters = parse_header( form_header_value, form_parameters = parse_header(
form_line[colon_index + 2:]) form_line[colon_index + 2:])
if form_header_field == 'Content-Disposition': if form_header_field.lower() == 'content-disposition':
if 'filename' in form_parameters: if 'filename' in form_parameters:
file_name = form_parameters['filename'] file_name = form_parameters['filename']
field_name = form_parameters.get('name') field_name = form_parameters.get('name')
elif form_header_field == 'Content-Type': elif form_header_field.lower() == 'content-type':
file_type = form_header_value file_type = form_header_value
post_data = form_part[line_index:-4] post_data = form_part[line_index:-4]

View File

@ -259,20 +259,26 @@ def test_post_form_urlencoded():
assert request.form.get('test') == 'OK' assert request.form.get('test') == 'OK'
@pytest.mark.parametrize(
def test_post_form_multipart_form_data(): 'payload', [
'------sanic\r\n' \
'Content-Disposition: form-data; name="test"\r\n' \
'\r\n' \
'OK\r\n' \
'------sanic--\r\n',
'------sanic\r\n' \
'content-disposition: form-data; name="test"\r\n' \
'\r\n' \
'OK\r\n' \
'------sanic--\r\n',
])
def test_post_form_multipart_form_data(payload):
app = Sanic('test_post_form_multipart_form_data') app = Sanic('test_post_form_multipart_form_data')
@app.route('/', methods=['POST']) @app.route('/', methods=['POST'])
async def handler(request): async def handler(request):
return text('OK') return text('OK')
payload = '------sanic\r\n' \
'Content-Disposition: form-data; name="test"\r\n' \
'\r\n' \
'OK\r\n' \
'------sanic--\r\n'
headers = {'content-type': 'multipart/form-data; boundary=----sanic'} headers = {'content-type': 'multipart/form-data; boundary=----sanic'}
request, response = app.test_client.post(data=payload, headers=headers) request, response = app.test_client.post(data=payload, headers=headers)