chore: Bump async-tungstenite to 0.23 (and tungstenite to 0.20.1) (#15039)
Release Notes: - N/A
This commit is contained in:
parent
7ae305ac0d
commit
4d65f7eea3
5 changed files with 32 additions and 65 deletions
|
@ -20,7 +20,7 @@ test-support = ["sqlite"]
|
|||
[dependencies]
|
||||
anthropic.workspace = true
|
||||
anyhow.workspace = true
|
||||
async-tungstenite = "0.16"
|
||||
async-tungstenite = "0.23"
|
||||
aws-config = { version = "1.1.5" }
|
||||
aws-sdk-s3 = { version = "1.15.0" }
|
||||
axum = { version = "0.6", features = ["json", "headers", "ws"] }
|
||||
|
|
|
@ -12,7 +12,7 @@ use crate::{
|
|||
executor::Executor,
|
||||
AppState, Error, RateLimit, RateLimiter, Result,
|
||||
};
|
||||
use anyhow::{anyhow, Context as _};
|
||||
use anyhow::{anyhow, bail, Context as _};
|
||||
use async_tungstenite::tungstenite::{
|
||||
protocol::CloseFrame as TungsteniteCloseFrame, Message as TungsteniteMessage,
|
||||
};
|
||||
|
@ -1392,7 +1392,13 @@ pub async fn handle_websocket_request(
|
|||
let socket = socket
|
||||
.map_ok(to_tungstenite_message)
|
||||
.err_into()
|
||||
.with(|message| async move { Ok(to_axum_message(message)) });
|
||||
.with(|message| async move {
|
||||
if let Some(message) = to_axum_message(message) {
|
||||
Ok(message)
|
||||
} else {
|
||||
bail!("Could not convert a tungstenite message to axum message");
|
||||
}
|
||||
});
|
||||
let connection = Connection::new(Box::pin(socket));
|
||||
async move {
|
||||
server
|
||||
|
@ -5154,16 +5160,21 @@ async fn get_private_user_info(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn to_axum_message(message: TungsteniteMessage) -> AxumMessage {
|
||||
fn to_axum_message(message: TungsteniteMessage) -> Option<AxumMessage> {
|
||||
match message {
|
||||
TungsteniteMessage::Text(payload) => AxumMessage::Text(payload),
|
||||
TungsteniteMessage::Binary(payload) => AxumMessage::Binary(payload),
|
||||
TungsteniteMessage::Ping(payload) => AxumMessage::Ping(payload),
|
||||
TungsteniteMessage::Pong(payload) => AxumMessage::Pong(payload),
|
||||
TungsteniteMessage::Close(frame) => AxumMessage::Close(frame.map(|frame| AxumCloseFrame {
|
||||
code: frame.code.into(),
|
||||
reason: frame.reason,
|
||||
})),
|
||||
TungsteniteMessage::Text(payload) => Some(AxumMessage::Text(payload)),
|
||||
TungsteniteMessage::Binary(payload) => Some(AxumMessage::Binary(payload)),
|
||||
TungsteniteMessage::Ping(payload) => Some(AxumMessage::Ping(payload)),
|
||||
TungsteniteMessage::Pong(payload) => Some(AxumMessage::Pong(payload)),
|
||||
TungsteniteMessage::Close(frame) => {
|
||||
Some(AxumMessage::Close(frame.map(|frame| AxumCloseFrame {
|
||||
code: frame.code.into(),
|
||||
reason: frame.reason,
|
||||
})))
|
||||
}
|
||||
// we can ignore `Frame` frames as recommended by the tungstenite maintainers
|
||||
// https://github.com/snapview/tungstenite-rs/issues/268
|
||||
TungsteniteMessage::Frame(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue