You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey there, I was wondering if there was a way to reply back to the client about the error that had occurred on accept_async but I can't figure out anyway to do so.
This is what I thought of at first:
let ws_stream = ifletOk(ws_stream) = tokio_tungstenite::accept_async(stream).await{
ws_stream
}else{
stream
.write_all(&make_response("Error, are you using a WS client?","HTTP/1.1 400 Bad Request\r\n\r\n",)).await.expect("Error while sending the msg");return;};fnmake_response(content:&str,status_line:&str) -> Vec<u8>{format!("{}\r\nContent-Length: {}\r\n\r\n{}",
status_line,
content.len(),
content
).as_bytes().to_vec()}
But as you can obviously see, the stream is moved to accept_async function thus cannot be used again. Is there any other way to achieve this? I looked through as many issues as I could but I couldn't an issue related to this. Thanks and sorry if this is dumb as I'm fairly new to rust and tokio-tungstenite.
The text was updated successfully, but these errors were encountered:
If you pass a stream to tokio-tungstenite, it will consume it (generally, there is no guarantee that the stream is usable after as often it's closed by the time you encounter an error).
However, if you're talking about a handshake phase only, this issue has been discussed here: snapview/tungstenite-rs#51
Hey there, I was wondering if there was a way to reply back to the client about the error that had occurred on
accept_async
but I can't figure out anyway to do so.This is what I thought of at first:
But as you can obviously see, the
stream
is moved toaccept_async
function thus cannot be used again. Is there any other way to achieve this? I looked through as many issues as I could but I couldn't an issue related to this. Thanks and sorry if this is dumb as I'm fairly new to rust and tokio-tungstenite.The text was updated successfully, but these errors were encountered: