diff options
author | Maximilian Hils <git@maximilianhils.com> | 2015-09-17 02:14:14 +0200 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2015-09-17 02:14:14 +0200 |
commit | dad9f06cb9403ac88d31d0ba8422034df2bc5078 (patch) | |
tree | d69ea509a4cfd9549f4a602966bd9309f8853b3c /netlib/http/models.py | |
parent | e1659f3fcf83b5993b776a4ef3d2de70fbe27aa2 (diff) | |
download | mitmproxy-dad9f06cb9403ac88d31d0ba8422034df2bc5078.tar.gz mitmproxy-dad9f06cb9403ac88d31d0ba8422034df2bc5078.tar.bz2 mitmproxy-dad9f06cb9403ac88d31d0ba8422034df2bc5078.zip |
organize exceptions, improve content-length handling
Diffstat (limited to 'netlib/http/models.py')
-rw-r--r-- | netlib/http/models.py | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/netlib/http/models.py b/netlib/http/models.py index 2d09535c..b4446ecb 100644 --- a/netlib/http/models.py +++ b/netlib/http/models.py @@ -231,7 +231,7 @@ class Request(object): self.path = path self.httpversion = httpversion self.headers = headers - self.body = body + self._body = body self.timestamp_start = timestamp_start self.timestamp_end = timestamp_end self.form_out = form_out or form_in @@ -453,6 +453,16 @@ class Request(object): self.scheme, self.host, self.port, self.path = parts @property + def body(self): + return self._body + + @body.setter + def body(self, body): + self._body = body + if isinstance(body, bytes): + self.headers["Content-Length"] = str(len(body)).encode() + + @property def content(self): # pragma: no cover # TODO: remove deprecated getter return self.body @@ -488,7 +498,7 @@ class Response(object): self.status_code = status_code self.msg = msg self.headers = headers - self.body = body + self._body = body self.timestamp_start = timestamp_start self.timestamp_end = timestamp_end @@ -552,6 +562,16 @@ class Response(object): self.headers.set_all("Set-Cookie", values) @property + def body(self): + return self._body + + @body.setter + def body(self, body): + self._body = body + if isinstance(body, bytes): + self.headers["Content-Length"] = str(len(body)).encode() + + @property def content(self): # pragma: no cover # TODO: remove deprecated getter return self.body |