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 <damien@micropython.org>
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy