kopia lustrzana https://github.com/micropython/micropython-lib
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>pull/941/head
rodzic
86df723301
commit
05a56c3cad
|
@ -269,7 +269,7 @@ class ClientSession:
|
||||||
return _WSRequestContextManager(self, self._ws_connect(url, ssl=ssl))
|
return _WSRequestContextManager(self, self._ws_connect(url, ssl=ssl))
|
||||||
|
|
||||||
async def _ws_connect(self, url, ssl=None):
|
async def _ws_connect(self, url, ssl=None):
|
||||||
ws_client = WebSocketClient(None)
|
ws_client = WebSocketClient(self._base_headers.copy())
|
||||||
await ws_client.connect(url, ssl=ssl, handshake_request=self.request_raw)
|
await ws_client.connect(url, ssl=ssl, handshake_request=self.request_raw)
|
||||||
self._reader = ws_client.reader
|
self._reader = ws_client.reader
|
||||||
return ClientWebSocketResponse(ws_client)
|
return ClientWebSocketResponse(ws_client)
|
||||||
|
|
|
@ -136,7 +136,7 @@ class WebSocketClient:
|
||||||
return frame + payload
|
return frame + payload
|
||||||
|
|
||||||
async def handshake(self, uri, ssl, req):
|
async def handshake(self, uri, ssl, req):
|
||||||
headers = {}
|
headers = self.params
|
||||||
_http_proto = "http" if uri.protocol != "wss" else "https"
|
_http_proto = "http" if uri.protocol != "wss" else "https"
|
||||||
url = f"{_http_proto}://{uri.hostname}:{uri.port}{uri.path or '/'}"
|
url = f"{_http_proto}://{uri.hostname}:{uri.port}{uri.path or '/'}"
|
||||||
key = binascii.b2a_base64(bytes(random.getrandbits(8) for _ in range(16)))[:-1]
|
key = binascii.b2a_base64(bytes(random.getrandbits(8) for _ in range(16)))[:-1]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
metadata(
|
metadata(
|
||||||
description="HTTP client module for MicroPython asyncio module",
|
description="HTTP client module for MicroPython asyncio module",
|
||||||
version="0.0.4",
|
version="0.0.5",
|
||||||
pypi="aiohttp",
|
pypi="aiohttp",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue