case-insensitive check for header fields
This commit is contained in:
parent
39ea434513
commit
3d75e6ed95
|
@ -242,11 +242,11 @@ def parse_multipart_form(body, boundary):
|
|||
form_header_value, form_parameters = parse_header(
|
||||
form_line[colon_index + 2:])
|
||||
|
||||
if form_header_field == 'Content-Disposition':
|
||||
if form_header_field.lower() == 'content-disposition':
|
||||
if 'filename' in form_parameters:
|
||||
file_name = form_parameters['filename']
|
||||
field_name = form_parameters.get('name')
|
||||
elif form_header_field == 'Content-Type':
|
||||
elif form_header_field.lower() == 'content-type':
|
||||
file_type = form_header_value
|
||||
|
||||
post_data = form_part[line_index:-4]
|
||||
|
|
|
@ -259,20 +259,26 @@ def test_post_form_urlencoded():
|
|||
|
||||
assert request.form.get('test') == 'OK'
|
||||
|
||||
|
||||
def test_post_form_multipart_form_data():
|
||||
@pytest.mark.parametrize(
|
||||
'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.route('/', methods=['POST'])
|
||||
async def handler(request):
|
||||
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'}
|
||||
|
||||
request, response = app.test_client.post(data=payload, headers=headers)
|
||||
|
|
Loading…
Reference in New Issue
Block a user