diff options
author | Thomas Kriechbaumer <thomas@kriechbaumer.name> | 2015-07-15 22:32:14 +0200 |
---|---|---|
committer | Thomas Kriechbaumer <thomas@kriechbaumer.name> | 2015-07-22 15:30:51 +0200 |
commit | bab6cbff1e5444aea72a188d57812130c375e0f0 (patch) | |
tree | 5b33c11cf076a099a039fa8e8494acf5b1eff07e /netlib/http/http1/protocol.py | |
parent | f50deb7b763d093a22a4d331e16465a2fb0329cf (diff) | |
download | mitmproxy-bab6cbff1e5444aea72a188d57812130c375e0f0.tar.gz mitmproxy-bab6cbff1e5444aea72a188d57812130c375e0f0.tar.bz2 mitmproxy-bab6cbff1e5444aea72a188d57812130c375e0f0.zip |
extract authentication methods from protocol
Diffstat (limited to 'netlib/http/http1/protocol.py')
-rw-r--r-- | netlib/http/http1/protocol.py | 39 |
1 files changed, 2 insertions, 37 deletions
diff --git a/netlib/http/http1/protocol.py b/netlib/http/http1/protocol.py index 0f7a0bd3..97c119a9 100644 --- a/netlib/http/http1/protocol.py +++ b/netlib/http/http1/protocol.py @@ -85,22 +85,9 @@ def read_chunked(fp, limit, is_request): return -def get_header_tokens(headers, key): - """ - Retrieve all tokens for a header key. A number of different headers - follow a pattern where each header line can containe comma-separated - tokens, and headers can be set multiple times. - """ - toks = [] - for i in headers[key]: - for j in i.split(","): - toks.append(j.strip()) - return toks - - def has_chunked_encoding(headers): return "chunked" in [ - i.lower() for i in get_header_tokens(headers, "transfer-encoding") + i.lower() for i in http.get_header_tokens(headers, "transfer-encoding") ] @@ -123,28 +110,6 @@ def parse_http_protocol(s): return major, minor -def parse_http_basic_auth(s): - # TODO: check if this is HTTP/1 only - otherwise move it to netlib.http.semantics - words = s.split() - if len(words) != 2: - return None - scheme = words[0] - try: - user = binascii.a2b_base64(words[1]) - except binascii.Error: - return None - parts = user.split(':') - if len(parts) != 2: - return None - return scheme, parts[0], parts[1] - - -def assemble_http_basic_auth(scheme, username, password): - # TODO: check if this is HTTP/1 only - otherwise move it to netlib.http.semantics - v = binascii.b2a_base64(username + ":" + password) - return scheme + " " + v - - def parse_init(line): try: method, url, protocol = string.split(line) @@ -221,7 +186,7 @@ def connection_close(httpversion, headers): """ # At first, check if we have an explicit Connection header. if "connection" in headers: - toks = get_header_tokens(headers, "connection") + toks = http.get_header_tokens(headers, "connection") if "close" in toks: return True elif "keep-alive" in toks: |