I'm trying to make a web server in Rust for a simple browser game. I want the server to be able to deliver pages through HTTPS, but also be able to communicate through WebSockets. I'm planning to put this server on Heroku, but since they only allow one port per application I have to make the WebSocket server operate on the same port as the other HTTPS code.
It seems like this is possible with crates like rust-websocket
, but that crate uses an outdated version of hyper
and seems to be no longer maintained. The crate tokio_tungstenite
is much more up to date.
The problem is that both hyper
and tungstenite
have their own implementation of the HTTP protocol that WebSockets operate over with no way to convert between the two. This means that once an HTTPS request has been parsed by either hyper
or tungstenite
there is no way to continue the processing by the other part, so you can't really try to connect the WebSocket and match on an error in tungstenite
and process it by hyper
, nor can you parse the request by hyper
and check if it's a WebSocket request and send it over to tungstenite
. Is there any way to resolve this problem?