fix subprotocol for granian

This commit is contained in:
Khaleel Al-Adhami 2025-01-27 11:34:42 -08:00
parent 709c6dedf2
commit ed3955a59a

View File

@ -419,11 +419,12 @@ class App(MiddlewareMixin, LifespanMixin):
if ( if (
message["type"] == "websocket.accept" message["type"] == "websocket.accept"
and protocol_key in headers and protocol_key in headers
and isinstance(
(subprotocol := headers[protocol_key]), bytes
)
): ):
message["headers"] = [ message["subprotocol"] = subprotocol.decode()
*message.get("headers", []),
(b"sec-websocket-protocol", headers[protocol_key]),
]
return await original_send(message) return await original_send(message)
return await self.app(scope, receive, modified_send) return await self.app(scope, receive, modified_send)