-
-
Notifications
You must be signed in to change notification settings - Fork 713
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Usability of the WebSocket filter #257
Comments
ps: |
Looking a bit more into the /// Return the bytes of this message.
pub fn as_bytes(&self) -> &[u8] {
match self.inner {
protocol::Message::Text(ref s) => s.as_bytes(),
protocol::Message::Binary(ref v) => v,
_ => unreachable!(),
}
} |
Im running into some more trouble looking at the error handling. The latter one would mean parsing textual error messages back into some meaningful enum to be able to act on that. I don't think I want to go there. So not only does it encapsulate all the useful information from the Btw, it's perfectly fine to use the replacement method of |
Thanks for writing this all up, we've been slowly chipping away at it. I think the majority is complete, with these notes:
|
With that in mind, I'm going to close this. If there's desire for continuing a specific point, we can open a focused issue for it. |
I'm implementing a lib that provides AsyncRead/AsyncWrite on top of websockets, to enable codec based communication between wasm code running in the browser and a server.
The wasm part is published, but the server part turns out to be more of a challenge. Since applications with a web frontend almost always have to serve static files, it makes sense to write this library as to be compatible with other crates like hyper and warp. This makes it possible for people to upgrade http connections benefiting from the convenience, not having to handle TLS separately and so on.
So it would seem the most appropriate input for my library would be to take in an object that implements
Stream<Result<tungstenite::Message, tungstenite::Error>>
andSink<tungstenite::Message, Error=tungstenite::Error>
and return an object that implementsAsyncRead
/AsyncWrite
. So I had a look at the warp ws module to see how to go about providing compatibility with warp and I'm running into some blockers:warp does not return the tungstenite types like tokio-tungstenite. This means I'm obliged to create my own type which implements
From<warp::ws::Message>
andFrom<warp::Error>
. And creating similar conversion from tungstenite types to provide compatibility with raw tungstenite or tokio-tungstenite connections. In itself this is not convenient, but it's not the end of the world, it can be done. Is it important for warp to not expose dependency types in the public API? If not, could we at least allow access to the inner type, or provideInto<tungstenite::Message> for warp::ws::Message
so that we can access the inner type?warp::ws::Message
does not provide theCloseFrame
from tungstenite, making it impossible for the client code to detect that the websocket client disconnects cleanly and read the close code and reason.warp::ws::Message
returns the data contained in the message as a&[u8]
. Withtungstenite::Message
which is an enum, I can destructure in order to get the innerVec<u8>
orString
without making an extra copy of the data. Withwarp::ws::Message
this doesn't seem possible if I need to store the data in a new type. I'm not even sure that I couldmem::swap
a&[u8]
to obtain aVec<u8>
. If that's possible, than this is not an issue. If the copy is necessary I won't use warp until this changes, and I will look for a more low-level solution like hyper->tokio-tungstenite. I suppose I could just make my type an enum over types from both crates, which means I can access the data by reference where it is actually needed, but it will result in quite some code bloat on my part, and maybe it would be nice to add an api which takesself
by value and returns the inner data by value.tungstenite::Message
provides this copyless conversion withInto<Vec<u8>>
.I wonder how these issues can best be resolved. I shared some other ideas of how we could reduce redundency of websocket code in the ecosystem here.
The text was updated successfully, but these errors were encountered: