made field name mandatory in multipart/form-data headers
A field name in the Content-Disposition header is required by the multipart/form-data spec. If one field/part does not have it, it will be omitted from the request. When this happens, we log it to DEBUG.
This commit is contained in:
parent
27108334f1
commit
5c341a2b00
|
@ -18,7 +18,7 @@ except ImportError:
|
||||||
json_loads = json.loads
|
json_loads = json.loads
|
||||||
|
|
||||||
from sanic.exceptions import InvalidUsage
|
from sanic.exceptions import InvalidUsage
|
||||||
from sanic.log import error_logger
|
from sanic.log import error_logger, logger
|
||||||
|
|
||||||
DEFAULT_HTTP_CONTENT_TYPE = "application/octet-stream"
|
DEFAULT_HTTP_CONTENT_TYPE = "application/octet-stream"
|
||||||
|
|
||||||
|
@ -309,6 +309,7 @@ def parse_multipart_form(body, boundary):
|
||||||
content_type = form_header_value
|
content_type = form_header_value
|
||||||
content_charset = form_parameters.get('charset', 'utf-8')
|
content_charset = form_parameters.get('charset', 'utf-8')
|
||||||
|
|
||||||
|
if field_name:
|
||||||
post_data = form_part[line_index:-4]
|
post_data = form_part[line_index:-4]
|
||||||
if file_name:
|
if file_name:
|
||||||
file = File(type=content_type, name=file_name, body=post_data)
|
file = File(type=content_type, name=file_name, body=post_data)
|
||||||
|
@ -322,5 +323,7 @@ def parse_multipart_form(body, boundary):
|
||||||
fields[field_name].append(value)
|
fields[field_name].append(value)
|
||||||
else:
|
else:
|
||||||
fields[field_name] = [value]
|
fields[field_name] = [value]
|
||||||
|
else:
|
||||||
|
logger.debug('Form-data field does not have a name parameter in the Content-Disposition header')
|
||||||
|
|
||||||
return fields, files
|
return fields, files
|
||||||
|
|
Loading…
Reference in New Issue
Block a user