diff options
| -rw-r--r-- | mitmproxy/models/http.py | 48 | 
1 files changed, 17 insertions, 31 deletions
diff --git a/mitmproxy/models/http.py b/mitmproxy/models/http.py index d56eb29a..8c5524e2 100644 --- a/mitmproxy/models/http.py +++ b/mitmproxy/models/http.py @@ -1,30 +1,14 @@  from __future__ import absolute_import, print_function, division  import cgi -import warnings -from mitmproxy.models.flow import Flow +from mitmproxy.models import flow +from netlib import http  from netlib import version -from netlib.http import Headers -from netlib.http import Request -from netlib.http import Response -from netlib.http import status_codes -from netlib.tcp import Address +from netlib import tcp -class MessageMixin(object): - -    def get_decoded_content(self): -        """ -            Returns the decoded content based on the current Content-Encoding -            header. -            Doesn't change the message iteself or its headers. -        """ -        warnings.warn(".get_decoded_content() is deprecated, please use .content directly instead.", DeprecationWarning) -        return self.content - - -class HTTPRequest(MessageMixin, Request): +class HTTPRequest(http.Request):      """      A mitmproxy HTTP request. @@ -49,7 +33,7 @@ class HTTPRequest(MessageMixin, Request):              stickycookie=False,              stickyauth=False,      ): -        Request.__init__( +        http.Request.__init__(              self,              first_line_format,              method, @@ -110,7 +94,7 @@ class HTTPRequest(MessageMixin, Request):          return id(self) -class HTTPResponse(MessageMixin, Response): +class HTTPResponse(http.Response):      """      A mitmproxy HTTP response. @@ -129,7 +113,7 @@ class HTTPResponse(MessageMixin, Response):              timestamp_end=None,              is_replay=False      ): -        Response.__init__( +        http.Response.__init__(              self,              http_version,              status_code, @@ -161,7 +145,7 @@ class HTTPResponse(MessageMixin, Response):          return resp -class HTTPFlow(Flow): +class HTTPFlow(flow.Flow):      """      A HTTPFlow is a collection of objects representing a single HTTP @@ -188,7 +172,7 @@ class HTTPFlow(Flow):          self.response = None          """@type: HTTPResponse""" -    _stateobject_attributes = Flow._stateobject_attributes.copy() +    _stateobject_attributes = flow.Flow._stateobject_attributes.copy()      _stateobject_attributes.update(          request=HTTPRequest,          response=HTTPResponse @@ -225,7 +209,7 @@ class HTTPFlow(Flow):  def make_error_response(status_code, message, headers=None): -    response = status_codes.RESPONSES.get(status_code, "Unknown") +    response = http.status_codes.RESPONSES.get(status_code, "Unknown")      body = """          <html>              <head> @@ -237,7 +221,7 @@ def make_error_response(status_code, message, headers=None):      body = body.encode("utf8", "replace")      if not headers: -        headers = Headers( +        headers = http.Headers(              Server=version.MITMPROXY,              Connection="close",              Content_Length=str(len(body)), @@ -254,10 +238,10 @@ def make_error_response(status_code, message, headers=None):  def make_connect_request(address): -    address = Address.wrap(address) +    address = tcp.Address.wrap(address)      return HTTPRequest(          "authority", b"CONNECT", None, address.host, address.port, None, b"HTTP/1.1", -        Headers(), b"" +        http.Headers(), b""      ) @@ -268,8 +252,10 @@ def make_connect_response(http_version):          http_version,          200,          b"Connection established", -        Headers(), +        http.Headers(),          b"",      ) -expect_continue_response = HTTPResponse(b"HTTP/1.1", 100, b"Continue", Headers(), b"") +expect_continue_response = HTTPResponse( +    b"HTTP/1.1", 100, b"Continue", http.Headers(), b"" +)  | 
