mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
[sans-io] make context.server non-optional
this makes for a nicer API, we just check for a missing address now.
This commit is contained in:
parent
edaf3219fc
commit
c8f1b3d7f9
@ -27,8 +27,9 @@ class Client(Connection):
|
||||
class Server(Connection):
|
||||
sni: Union[bytes, bool] = True
|
||||
"""True: client SNI, False: no SNI, bytes: custom value"""
|
||||
address: Optional[tuple]
|
||||
|
||||
def __init__(self, address):
|
||||
def __init__(self, address: Optional[tuple]):
|
||||
self.address = address
|
||||
|
||||
|
||||
@ -38,17 +39,16 @@ class Context:
|
||||
"""
|
||||
|
||||
client: Client
|
||||
server: Optional[Server]
|
||||
server: Server
|
||||
options: Options
|
||||
layers: List["mitmproxy.proxy2.layer.Layer"]
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
client: Client,
|
||||
server: Optional[Server],
|
||||
options: Options,
|
||||
) -> None:
|
||||
self.client = client
|
||||
self.server = server
|
||||
self.options = options
|
||||
self.server = Server(None)
|
||||
self.layers = []
|
||||
|
@ -29,7 +29,7 @@ class ConnectionHandler(metaclass=abc.ABCMeta):
|
||||
addr = writer.get_extra_info('peername')
|
||||
|
||||
self.client = Client(addr)
|
||||
self.context = Context(self.client, None, options)
|
||||
self.context = Context(self.client, options)
|
||||
|
||||
if options.mode.startswith("reverse:"):
|
||||
self.layer = ReverseProxy(self.context)
|
||||
@ -83,6 +83,8 @@ class ConnectionHandler(metaclass=abc.ABCMeta):
|
||||
break
|
||||
|
||||
async def open_connection(self, command: commands.OpenConnection):
|
||||
if not command.connection.address:
|
||||
raise ValueError("Cannot open connection, no hostname given.")
|
||||
try:
|
||||
reader, writer = await asyncio.open_connection(
|
||||
*command.connection.address
|
||||
|
Loading…
Reference in New Issue
Block a user