python-trio / trio-websocket

WebSocket client and server implementation for Python Trio
MIT License
70 stars 26 forks source link

WebSocketConnection does not expose handshake path, etc. #17

Closed belm0 closed 6 years ago

belm0 commented 6 years ago

WebSocketConnection doesn't appear to expose information from the HTTP handshake, such as path.

This is a show stopper for my use case.

belm0 commented 6 years ago

I couldn't find this info anywhere within the WebSocketConnection internals, including _wsproto (host and resource are both None) and _socket.

belm0 commented 6 years ago

I believe this requires inspecting the event h11request when the wsproto ConnectionRequested event is received.

It seems that trio-websocket takes the approach of encapsulating wsproto as an implementation detail. So to follow this we would have to wrap all the details of the request...

For now I'll make a PR to expose path as a property on WebSocketConnection, and we can consider from there.

belm0 commented 6 years ago

A complication: the user handler is called prior to receiving ConnectionRequested. So with the current API, the user cannot know when the new path property will be valid.

For a simplistic API like this I suggest that the user handler only be called in the case of successful handshake.