mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 10:16:27 +00:00
Merge pull request #2530 from mhils/nicer-clienthello-alpns
Improve ClientHello.alpn_protocols API
This commit is contained in:
commit
7c650aa53b
@ -292,7 +292,7 @@ class TlsClientHello:
|
|||||||
if self._client_hello.extensions:
|
if self._client_hello.extensions:
|
||||||
for extension in self._client_hello.extensions.extensions:
|
for extension in self._client_hello.extensions.extensions:
|
||||||
if extension.type == 0x10:
|
if extension.type == 0x10:
|
||||||
return list(extension.body.alpn_protocols)
|
return list(x.name for x in extension.body.alpn_protocols)
|
||||||
return []
|
return []
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -519,8 +519,8 @@ class TlsLayer(base.Layer):
|
|||||||
# We only support http/1.1 and h2.
|
# We only support http/1.1 and h2.
|
||||||
# If the server only supports spdy (next to http/1.1), it may select that
|
# 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.
|
# and mitmproxy would enter TCP passthrough mode, which we want to avoid.
|
||||||
alpn = [x.name for x in self._client_hello.alpn_protocols if
|
alpn = [x for x in self._client_hello.alpn_protocols if
|
||||||
not (x.name.startswith(b"h2-") or x.name.startswith(b"spdy"))]
|
not (x.startswith(b"h2-") or x.startswith(b"spdy"))]
|
||||||
if alpn and b"h2" in alpn and not self.config.options.http2:
|
if alpn and b"h2" in alpn and not self.config.options.http2:
|
||||||
alpn.remove(b"h2")
|
alpn.remove(b"h2")
|
||||||
|
|
||||||
|
@ -23,5 +23,4 @@ class TestClientHello:
|
|||||||
)
|
)
|
||||||
c = TlsClientHello(data)
|
c = TlsClientHello(data)
|
||||||
assert c.sni == 'example.com'
|
assert c.sni == 'example.com'
|
||||||
assert c.alpn_protocols[0].name == b'h2'
|
assert c.alpn_protocols == [b'h2', b'http/1.1']
|
||||||
assert c.alpn_protocols[1].name == b'http/1.1'
|
|
||||||
|
Loading…
Reference in New Issue
Block a user