diff options
author | Maximilian Hils <git@maximilianhils.com> | 2017-08-16 19:10:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-16 19:10:27 +0200 |
commit | 7c650aa53bc947207b2fcd0cbf195ba83a64252e (patch) | |
tree | 155c09ab8c0d234c62f5b88e83437e15e4ba51fa | |
parent | 92ab90bb89cb3a31ea1ba4cf6bd3912922693957 (diff) | |
parent | 74a04f41ee9032c240f8e8b24326516272f559ae (diff) | |
download | mitmproxy-7c650aa53bc947207b2fcd0cbf195ba83a64252e.tar.gz mitmproxy-7c650aa53bc947207b2fcd0cbf195ba83a64252e.tar.bz2 mitmproxy-7c650aa53bc947207b2fcd0cbf195ba83a64252e.zip |
Merge pull request #2530 from mhils/nicer-clienthello-alpns
Improve ClientHello.alpn_protocols API
-rw-r--r-- | mitmproxy/proxy/protocol/tls.py | 6 | ||||
-rw-r--r-- | test/mitmproxy/proxy/protocol/test_tls.py | 3 |
2 files changed, 4 insertions, 5 deletions
diff --git a/mitmproxy/proxy/protocol/tls.py b/mitmproxy/proxy/protocol/tls.py index b7bc6b1c..10eea4ae 100644 --- a/mitmproxy/proxy/protocol/tls.py +++ b/mitmproxy/proxy/protocol/tls.py @@ -292,7 +292,7 @@ class TlsClientHello: if self._client_hello.extensions: for extension in self._client_hello.extensions.extensions: if extension.type == 0x10: - return list(extension.body.alpn_protocols) + return list(x.name for x in extension.body.alpn_protocols) return [] @classmethod @@ -519,8 +519,8 @@ class TlsLayer(base.Layer): # We only support http/1.1 and h2. # If the server only supports spdy (next to http/1.1), it may select that # and mitmproxy would enter TCP passthrough mode, which we want to avoid. - alpn = [x.name for x in self._client_hello.alpn_protocols if - not (x.name.startswith(b"h2-") or x.name.startswith(b"spdy"))] + alpn = [x for x in self._client_hello.alpn_protocols if + not (x.startswith(b"h2-") or x.startswith(b"spdy"))] if alpn and b"h2" in alpn and not self.config.options.http2: alpn.remove(b"h2") diff --git a/test/mitmproxy/proxy/protocol/test_tls.py b/test/mitmproxy/proxy/protocol/test_tls.py index 980ba7bd..e17ee46f 100644 --- a/test/mitmproxy/proxy/protocol/test_tls.py +++ b/test/mitmproxy/proxy/protocol/test_tls.py @@ -23,5 +23,4 @@ class TestClientHello: ) c = TlsClientHello(data) assert c.sni == 'example.com' - assert c.alpn_protocols[0].name == b'h2' - assert c.alpn_protocols[1].name == b'http/1.1' + assert c.alpn_protocols == [b'h2', b'http/1.1'] |