diff options
| author | Aldo Cortesi <aldo@nullcube.com> | 2012-08-18 18:14:30 +1200 | 
|---|---|---|
| committer | Aldo Cortesi <aldo@nullcube.com> | 2012-08-18 18:14:30 +1200 | 
| commit | 53e453f72ede3b99fc36aca998ec78f8c186de1c (patch) | |
| tree | 3c8a3c0265da8422711e9a0694bfc92eda23a68f | |
| parent | 15e234558dc3ca2e7fb3a3ef73211994bf541584 (diff) | |
| download | mitmproxy-53e453f72ede3b99fc36aca998ec78f8c186de1c.tar.gz mitmproxy-53e453f72ede3b99fc36aca998ec78f8c186de1c.tar.bz2 mitmproxy-53e453f72ede3b99fc36aca998ec78f8c186de1c.zip | |
Use the new ODict get_first convenience function in a bunch of places.
| -rw-r--r-- | libmproxy/console/contentview.py | 18 | ||||
| -rw-r--r-- | libmproxy/console/flowview.py | 4 | ||||
| -rw-r--r-- | libmproxy/flow.py | 12 | 
3 files changed, 16 insertions, 18 deletions
| diff --git a/libmproxy/console/contentview.py b/libmproxy/console/contentview.py index 4b934ed5..e5881b6b 100644 --- a/libmproxy/console/contentview.py +++ b/libmproxy/console/contentview.py @@ -50,11 +50,9 @@ class ViewAuto:      prompt = ("auto", "a")      content_types = []      def __call__(self, hdrs, content, limit): -        ctype = hdrs.get("content-type") +        ctype = hdrs.get_first("content-type")          if ctype: -            ctype = ctype[0] -        ct = utils.parse_content_type(ctype) if ctype else None -        if ct: +            ct = utils.parse_content_type(ctype) if ctype else None              ct = "%s/%s"%(ct[0], ct[1])              if ct in content_types_map:                  return content_types_map[ct][0](hdrs, content, limit) @@ -199,9 +197,9 @@ class ViewMultipart:      prompt = ("multipart", "m")      content_types = ["multipart/form-data"]      def __call__(self, hdrs, content, limit): -        v = hdrs.get("content-type") +        v = hdrs.get_first("content-type")          if v: -            v = utils.parse_content_type(v[0]) +            v = utils.parse_content_type(v)              if not v:                  return              boundary = v[2].get("boundary") @@ -363,12 +361,12 @@ def get_content_view(viewmode, hdrItems, content, limit, logfunc):      hdrs = flow.ODictCaseless([list(i) for i in hdrItems]) -    enc = hdrs.get("content-encoding") -    if enc and enc[0] != "identity": -        decoded = encoding.decode(enc[0], content) +    enc = hdrs.get_first("content-encoding") +    if enc and enc != "identity": +        decoded = encoding.decode(enc, content)          if decoded:              content = decoded -            msg.append("[decoded %s]"%enc[0]) +            msg.append("[decoded %s]"%enc)      try:          ret = viewmode(hdrs, content, limit)      # Third-party viewers can fail in unexpected ways... diff --git a/libmproxy/console/flowview.py b/libmproxy/console/flowview.py index a6ee41eb..0106e075 100644 --- a/libmproxy/console/flowview.py +++ b/libmproxy/console/flowview.py @@ -555,8 +555,8 @@ class FlowView(common.WWrap):          elif key == "z":              if conn:                  self.flow.backup() -                e = conn.headers["content-encoding"] or ["identity"] -                if e[0] != "identity": +                e = conn.headers.get_first("content-encoding", "identity") +                if e != "identity":                      conn.decode()                  else:                      self.master.prompt_onekey( diff --git a/libmproxy/flow.py b/libmproxy/flow.py index 674197a4..2d016a14 100644 --- a/libmproxy/flow.py +++ b/libmproxy/flow.py @@ -134,9 +134,9 @@ class decoded(object):      """      def __init__(self, o):          self.o = o -        ce = o.headers["content-encoding"] -        if ce and ce[0] in encoding.ENCODINGS: -            self.ce = ce[0] +        ce = o.headers.get_first("content-encoding") +        if ce in encoding.ENCODINGS: +            self.ce = ce          else:              self.ce = None @@ -156,11 +156,11 @@ class HTTPMsg(controller.Msg):              removes the header. If there is no Content-Encoding header, no              action is taken.          """ -        ce = self.headers["content-encoding"] -        if not self.content or not ce or ce[0] not in encoding.ENCODINGS: +        ce = self.headers.get_first("content-encoding") +        if not self.content or ce not in encoding.ENCODINGS:              return          self.content = encoding.decode( -            ce[0], +            ce,              self.content          )          del self.headers["content-encoding"] | 
