Skip to content

Conversation

AuroraTea
Copy link
Contributor

The function binascii.b2a_base64() returns a bytes.
Here needs a string
Otherwise, the value of Sec-WebSocket-Key in the headers will be b'<BASE64-ENCODED_RANDOM_VALUE>'.
It means there will be b' at the beginning and ' at the end.

@AuroraTea AuroraTea force-pushed the patch-1 branch 2 times, most recently from b0d8fc9 to 8b51240 Compare April 14, 2024 11:42
@AuroraTea AuroraTea changed the title Fix type of Sec-WebSocket-Key in aiohttp_ws.py aiohttp: Fix type of Sec-WebSocket-Key in aiohttp_ws.py Apr 20, 2024
@@ -143,7 +143,7 @@ async def handshake(self, uri, ssl, req):
headers["Host"] = f"{uri.hostname}:{uri.port}"
headers["Connection"] = "Upgrade"
headers["Upgrade"] = "websocket"
headers["Sec-WebSocket-Key"] = key
headers["Sec-WebSocket-Key"] = key.decode("utf-8")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use str(key, "utf-8"), because the decode() method is not always available.

@AuroraTea AuroraTea force-pushed the patch-1 branch 2 times, most recently from e16fd20 to 082b5dd Compare May 15, 2024 12:15
The function `binascii.b2a_base64()` returns a `bytes`, but here needs a
string.  Otherwise, the value of `Sec-WebSocket-Key` in the headers will be
`b'<BASE64-ENCODED_RANDOM_VALUE>'`.

Signed-off-by: AuroraTea <1352685369@qq.com>
@dpgeorge dpgeorge merged commit 2b0d761 into micropython:master May 24, 2024
@dpgeorge
Copy link
Member

Thanks for updating. This is now merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants