mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-22 15:37:45 +00:00
[sans-io] better sockname/peername naming, refs #3896
This commit is contained in:
parent
c5cb0d2f0b
commit
f12b2b7e87
@ -17,9 +17,10 @@ class Connection:
|
||||
"""
|
||||
Connections exposed to the layers only contain metadata, no socket objects.
|
||||
"""
|
||||
address: Optional[tuple]
|
||||
local_address: Optional[tuple]
|
||||
state: ConnectionState
|
||||
peername: Optional[tuple]
|
||||
sockname: Optional[tuple]
|
||||
|
||||
tls: bool = False
|
||||
tls_established: bool = False
|
||||
certificate_chain: Optional[Sequence[certs.Cert]] = None
|
||||
@ -37,28 +38,34 @@ class Connection:
|
||||
|
||||
def __repr__(self):
|
||||
attrs = repr({
|
||||
k: {"cipher_list": lambda: f"<{len(v)} ciphers>"}.get(k,lambda: v)()
|
||||
k: {"cipher_list": lambda: f"<{len(v)} ciphers>"}.get(k, lambda: v)()
|
||||
for k, v in self.__dict__.items()
|
||||
})
|
||||
return f"{type(self).__name__}({attrs})"
|
||||
|
||||
|
||||
class Client(Connection):
|
||||
sni: Union[bytes, None] = None
|
||||
address: tuple
|
||||
state = ConnectionState.OPEN
|
||||
peername: tuple
|
||||
sockname: tuple
|
||||
|
||||
def __init__(self, address, local_address):
|
||||
self.address = address
|
||||
self.local_address = local_address
|
||||
sni: Union[bytes, None] = None
|
||||
|
||||
def __init__(self, peername, sockname):
|
||||
self.peername = peername
|
||||
self.sockname = sockname
|
||||
|
||||
|
||||
class Server(Connection):
|
||||
state = ConnectionState.CLOSED
|
||||
|
||||
peername = None
|
||||
sockname = None
|
||||
address: Optional[tuple]
|
||||
|
||||
sni = True
|
||||
"""True: client SNI, False: no SNI, bytes: custom value"""
|
||||
via: Optional[server_spec.ServerSpec] = None
|
||||
state = ConnectionState.CLOSED
|
||||
local_address = None
|
||||
|
||||
def __init__(self, address: Optional[tuple]):
|
||||
self.address = address
|
||||
|
@ -80,10 +80,10 @@ class ConnectionHandler(metaclass=abc.ABCMeta):
|
||||
timeout_watchdog: TimeoutWatchdog
|
||||
|
||||
def __init__(self, reader: asyncio.StreamReader, writer: asyncio.StreamWriter, options: moptions.Options) -> None:
|
||||
addr = writer.get_extra_info('peername')
|
||||
local_addr = writer.get_extra_info('sockname')
|
||||
|
||||
self.client = Client(addr, local_addr)
|
||||
self.client = Client(
|
||||
writer.get_extra_info('peername'),
|
||||
writer.get_extra_info('sockname')
|
||||
)
|
||||
self.context = Context(self.client, options)
|
||||
self.transports = {
|
||||
self.client: ConnectionIO(handler=None, reader=reader, writer=writer)
|
||||
@ -133,6 +133,8 @@ class ConnectionHandler(metaclass=abc.ABCMeta):
|
||||
self.transports[command.connection].reader = reader
|
||||
self.transports[command.connection].writer = writer
|
||||
command.connection.state = ConnectionState.OPEN
|
||||
command.connection.peername = writer.get_extra_info('peername')
|
||||
command.connection.sockname = writer.get_extra_info('sockname')
|
||||
self.server_event(events.OpenConnectionReply(command, None))
|
||||
try:
|
||||
await self.handle_connection(command.connection)
|
||||
|
@ -518,7 +518,6 @@ def test_proxy_chain(tctx, strategy):
|
||||
assert playbook
|
||||
|
||||
|
||||
@pytest.mark.xfail(reason="h11 enforces host headers by default")
|
||||
def test_no_headers(tctx):
|
||||
"""Test that we can correctly reassemble requests/responses with no headers."""
|
||||
server = Placeholder()
|
||||
|
Loading…
Reference in New Issue
Block a user