Merge pull request #6 from channelcat/master
fix(request.py): problem in case of request without content-type head…
This commit is contained in:
commit
aaee40aabd
|
@ -8,6 +8,12 @@ from ujson import loads as json_loads
|
|||
from .log import log
|
||||
|
||||
|
||||
DEFAULT_HTTP_CONTENT_TYPE = "application/octet-stream"
|
||||
# HTTP/1.1: https://www.w3.org/Protocols/rfc2616/rfc2616-sec7.html#sec7.2.1
|
||||
# > If the media type remains unknown, the recipient SHOULD treat it
|
||||
# > as type "application/octet-stream"
|
||||
|
||||
|
||||
class RequestParameters(dict):
|
||||
"""
|
||||
Hosts a dict with lists as values where get returns the first
|
||||
|
@ -68,14 +74,13 @@ class Request:
|
|||
@property
|
||||
def form(self):
|
||||
if self.parsed_form is None:
|
||||
self.parsed_form = {}
|
||||
self.parsed_files = {}
|
||||
content_type, parameters = parse_header(
|
||||
self.headers.get('Content-Type', ''))
|
||||
self.parsed_form = RequestParameters()
|
||||
self.parsed_files = RequestParameters()
|
||||
content_type = self.headers.get(
|
||||
'Content-Type', DEFAULT_HTTP_CONTENT_TYPE)
|
||||
content_type, parameters = parse_header(content_type)
|
||||
try:
|
||||
is_url_encoded = (
|
||||
content_type == 'application/x-www-form-urlencoded')
|
||||
if content_type is None or is_url_encoded:
|
||||
if content_type == 'application/x-www-form-urlencoded':
|
||||
self.parsed_form = RequestParameters(
|
||||
parse_qs(self.body.decode('utf-8')))
|
||||
elif content_type == 'multipart/form-data':
|
||||
|
@ -86,7 +91,6 @@ class Request:
|
|||
except Exception as e:
|
||||
log.exception(e)
|
||||
pass
|
||||
|
||||
return self.parsed_form
|
||||
|
||||
@property
|
||||
|
|
Loading…
Reference in New Issue
Block a user