diff options
| author | Aldo Cortesi <aldo@nullcube.com> | 2016-06-01 09:58:01 +1200 | 
|---|---|---|
| committer | Aldo Cortesi <aldo@nullcube.com> | 2016-06-01 09:58:01 +1200 | 
| commit | a061e4587772f4a87eb43d84f2ed358f7cc98fbd (patch) | |
| tree | 1aba05c9d0d6f654fe946897dcb8b5d9127a3de2 /netlib/http/headers.py | |
| parent | 06703542037d1c84b0dcb60c6d1c500a0d189e93 (diff) | |
| parent | a7abf8b731658b4e7ed8705f7a94a6a62f08d51d (diff) | |
| download | mitmproxy-a061e4587772f4a87eb43d84f2ed358f7cc98fbd.tar.gz mitmproxy-a061e4587772f4a87eb43d84f2ed358f7cc98fbd.tar.bz2 mitmproxy-a061e4587772f4a87eb43d84f2ed358f7cc98fbd.zip  | |
Merge branch 'master' of github.com:cortesi/mitmproxy
Diffstat (limited to 'netlib/http/headers.py')
| -rw-r--r-- | netlib/http/headers.py | 27 | 
1 files changed, 27 insertions, 0 deletions
diff --git a/netlib/http/headers.py b/netlib/http/headers.py index 6165fd61..fa7b7180 100644 --- a/netlib/http/headers.py +++ b/netlib/http/headers.py @@ -175,3 +175,30 @@ class Headers(MultiDict):              fields.append([name, value])          self.fields = fields          return replacements + + +def parse_content_type(c): +    """ +        A simple parser for content-type values. Returns a (type, subtype, +        parameters) tuple, where type and subtype are strings, and parameters +        is a dict. If the string could not be parsed, return None. + +        E.g. the following string: + +            text/html; charset=UTF-8 + +        Returns: + +            ("text", "html", {"charset": "UTF-8"}) +    """ +    parts = c.split(";", 1) +    ts = parts[0].split("/", 1) +    if len(ts) != 2: +        return None +    d = {} +    if len(parts) == 2: +        for i in parts[1].split(";"): +            clause = i.split("=", 1) +            if len(clause) == 2: +                d[clause[0].strip()] = clause[1].strip() +    return ts[0].lower(), ts[1].lower(), d  | 
