Tectu / malloy

A cross-platform C++20 library providing embeddable server & client components for HTTP and WebSocket.
BSD 3-Clause "New" or "Revised" License
66 stars 8 forks source link

WebSocket payload types #49

Closed Tectu closed 3 years ago

Tectu commented 3 years ago

As of today, the handler for handling incoming data via a WebSocket connection is defined as:

using handler_t = std::function<void(const malloy::http::request<>&, const std::shared_ptr<connection>&)>;

I've been reading through the corresponding documentation and I couldn't find any hard evidence that payloads send over WebSocket need to be HTTP requests. Any payload expressible as bytes can be sent via WebSocket.

@0x00002a as you introduced this change (before it was std::string) I was wondering what the rationale behind this is/was?

0x00002a commented 3 years ago

@Tectu See: #38, the request is needed for connection::accept, which must be called on the server side to actually establish the connection (this allows the server to do its own processing on whether to deny it or not). That is not the payload sent over websocket, that is the http upgrade request as parsed from the stream in http::connection. All the actual websocket stuff is done via connection later and kicked off by the user in the handler (and uses its own callbacks which use asio buffer concepts directly)

Tectu commented 3 years ago

🤦 - yeah, that makes perfect sense. Sorry for the noise!