Merge pull request #173 from jamielennox/parsed_body

Reparse the request body when setting body
This commit is contained in:
Gabriel Falcão 2016-05-26 16:34:53 -04:00
commit 17825e17bc
1 changed files with 14 additions and 2 deletions

View File

@ -146,7 +146,7 @@ class HTTPrettyRequest(BaseHTTPRequestHandler, BaseClass):
# unicode strings, it must be converted into a utf-8 encoded
# byte string
self.raw_headers = utf8(headers.strip())
self.body = utf8(body)
self._body = utf8(body)
# Now let's concatenate the headers with the body, and create
# `rfile` based on it
@ -185,7 +185,19 @@ class HTTPrettyRequest(BaseHTTPRequestHandler, BaseClass):
# And the body will be attempted to be parsed as
# `application/json` or `application/x-www-form-urlencoded`
self.parsed_body = self.parse_request_body(self.body)
self.parsed_body = self.parse_request_body(self._body)
@property
def body(self):
return self._body
@body.setter
def body(self, value):
self._body = utf8(value)
# And the body will be attempted to be parsed as
# `application/json` or `application/x-www-form-urlencoded`
self.parsed_body = self.parse_request_body(self._body)
def __nonzero__(self):
return bool(self.body) or bool(self.raw_headers)