Skip to content

Commit 7294374

Browse files
ruff format
1 parent 482399f commit 7294374

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

.github/workflows/check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
python-version: "3.x"
2222

2323
- run: npm ci
24-
- run: pip install mitmproxy ruff mypy
24+
- run: pip install mitmproxy ruff mypy # TODO I’m not sure what is the right way of doing this
2525

2626
# Run JS checks
2727
- run: npm run format:check

src/python/mitmproxy_addon.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
import websockets
55
import json
66

7+
78
async def send_ready_notification() -> None:
89
uri = "ws://localhost:8001"
9-
logging.info(f'sending mitmproxyReady JSON-RPC notification to {uri}')
10+
logging.info(f"sending mitmproxyReady JSON-RPC notification to {uri}")
1011
async with websockets.connect(uri) as websocket:
11-
notification_dto = { "jsonrpc": "2.0", "method": "mitmproxyReady" }
12+
notification_dto = {"jsonrpc": "2.0", "method": "mitmproxyReady"}
1213
data = json.dumps(notification_dto)
1314
await websocket.send(data)
1415

16+
1517
class MitmproxyAddon:
1618
def running(self) -> None:
1719
# tell the control API that we’re ready to receive traffic
@@ -21,12 +23,14 @@ def running(self) -> None:
2123
def request(self, flow: http.HTTPFlow) -> None:
2224
# To make sure that when running in local redirect mode (and hence intercepting all traffic from the test process) we don’t mess with traffic from the test process to the control API
2325
# TODO see extended comments re this in test-node.yml and why it hasn’t yet been an issue in practice on macOS
24-
if not flow.request.port in [80, 443]:
26+
if flow.request.port not in [80, 443]:
2527
return
2628

2729
# (b'Connection', b'Upgrade'), (b'Upgrade', b'websocket')
2830
intercept = MitmproxyAddon.is_websocket_upgrade_request(flow.request)
29-
logging.info(f'MitmproxyAddon {"intercepting" if intercept else "not intercepting"} `request` {flow.request.url}, headers {flow.request.headers}')
31+
logging.info(
32+
f'MitmproxyAddon {"intercepting" if intercept else "not intercepting"} `request` {flow.request.url}, headers {flow.request.headers}'
33+
)
3034
# pretty_host takes the "Host" header of the request into account,
3135
# which is useful in transparent mode where we usually only have the IP
3236
# otherwise.
@@ -38,18 +42,26 @@ def request(self, flow: http.HTTPFlow) -> None:
3842

3943
flow.request.host = "localhost"
4044
flow.request.port = 8002
41-
flow.request.scheme = 'http'
45+
flow.request.scheme = "http"
4246
# TODO understand how port fits into this
43-
flow.request.headers['Ably-Test-Host'] = original_host
47+
flow.request.headers["Ably-Test-Host"] = original_host
4448
match original_scheme:
45-
case 'http':
46-
flow.request.headers['Ably-Test-Proto'] = 'ws'
47-
case 'https':
48-
flow.request.headers['Ably-Test-Proto'] = 'wss'
49+
case "http":
50+
flow.request.headers["Ably-Test-Proto"] = "ws"
51+
case "https":
52+
flow.request.headers["Ably-Test-Proto"] = "wss"
4953

5054
@staticmethod
5155
def is_websocket_upgrade_request(request: http.Request) -> bool:
5256
# TODO this request handling is a bit fragile, the special case for `split` is just to handle the fact that Firefox sends 'Connection: keep-alive, Upgrade'
53-
return True if 'Connection' in request.headers and ('Upgrade' in request.headers['Connection'].split(", ")) and 'Upgrade' in request.headers and request.headers['Upgrade'] == 'websocket' else False
57+
return (
58+
True
59+
if "Connection" in request.headers
60+
and ("Upgrade" in request.headers["Connection"].split(", "))
61+
and "Upgrade" in request.headers
62+
and request.headers["Upgrade"] == "websocket"
63+
else False
64+
)
65+
5466

5567
addons = [MitmproxyAddon()]

0 commit comments

Comments
 (0)