Skip to content

Commit 05a56c3

Browse files
jomasnashdpgeorge
authored andcommitted
aiohttp: Allow headers to be passed to a WebSocketClient.
This commit will make it possible to add headers to a Websocket. Among other things, this allows making a connection to online MQTT brokers over websocket, using the header entry "Sec-WebSocket-Protocol":"mqtt" in the handshake of the upgrade protocol. Signed-off-by: Damien George <[email protected]>
1 parent 86df723 commit 05a56c3

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

python-ecosys/aiohttp/aiohttp/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def ws_connect(self, url, ssl=None):
269269
return _WSRequestContextManager(self, self._ws_connect(url, ssl=ssl))
270270

271271
async def _ws_connect(self, url, ssl=None):
272-
ws_client = WebSocketClient(None)
272+
ws_client = WebSocketClient(self._base_headers.copy())
273273
await ws_client.connect(url, ssl=ssl, handshake_request=self.request_raw)
274274
self._reader = ws_client.reader
275275
return ClientWebSocketResponse(ws_client)

python-ecosys/aiohttp/aiohttp/aiohttp_ws.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def _encode_websocket_frame(cls, opcode, payload):
136136
return frame + payload
137137

138138
async def handshake(self, uri, ssl, req):
139-
headers = {}
139+
headers = self.params
140140
_http_proto = "http" if uri.protocol != "wss" else "https"
141141
url = f"{_http_proto}://{uri.hostname}:{uri.port}{uri.path or '/'}"
142142
key = binascii.b2a_base64(bytes(random.getrandbits(8) for _ in range(16)))[:-1]

python-ecosys/aiohttp/manifest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
metadata(
22
description="HTTP client module for MicroPython asyncio module",
3-
version="0.0.4",
3+
version="0.0.5",
44
pypi="aiohttp",
55
)
66

0 commit comments

Comments
 (0)