mirror of
https://github.com/tokio-rs/axum.git
synced 2025-01-05 18:27:07 +01:00
Update to tokio-tungstenite 0.17 (#791)
Fixes https://github.com/tokio-rs/axum/issues/781
This commit is contained in:
parent
07e8a6d8fe
commit
4ccc4bea71
3 changed files with 25 additions and 16 deletions
|
@ -57,6 +57,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
requests ([#734])
|
requests ([#734])
|
||||||
- **fixed:** Fix wrong `content-length` for `HEAD` requests to endpoints that returns chunked
|
- **fixed:** Fix wrong `content-length` for `HEAD` requests to endpoints that returns chunked
|
||||||
responses ([#755])
|
responses ([#755])
|
||||||
|
- **changed:** Update to tokio-tungstenite 0.17 ([#791])
|
||||||
|
|
||||||
[#644]: https://github.com/tokio-rs/axum/pull/644
|
[#644]: https://github.com/tokio-rs/axum/pull/644
|
||||||
[#665]: https://github.com/tokio-rs/axum/pull/665
|
[#665]: https://github.com/tokio-rs/axum/pull/665
|
||||||
|
@ -67,6 +68,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
[#734]: https://github.com/tokio-rs/axum/pull/734
|
[#734]: https://github.com/tokio-rs/axum/pull/734
|
||||||
[#755]: https://github.com/tokio-rs/axum/pull/755
|
[#755]: https://github.com/tokio-rs/axum/pull/755
|
||||||
[#783]: https://github.com/tokio-rs/axum/pull/783
|
[#783]: https://github.com/tokio-rs/axum/pull/783
|
||||||
|
[#791]: https://github.com/tokio-rs/axum/pull/791
|
||||||
|
|
||||||
# 0.4.4 (13. January, 2022)
|
# 0.4.4 (13. January, 2022)
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ multer = { optional = true, version = "2.0.0" }
|
||||||
serde_json = { version = "1.0", optional = true, features = ["raw_value"] }
|
serde_json = { version = "1.0", optional = true, features = ["raw_value"] }
|
||||||
serde_urlencoded = { version = "0.7", optional = true }
|
serde_urlencoded = { version = "0.7", optional = true }
|
||||||
sha-1 = { optional = true, version = "0.10" }
|
sha-1 = { optional = true, version = "0.10" }
|
||||||
tokio-tungstenite = { optional = true, version = "0.16" }
|
tokio-tungstenite = { optional = true, version = "0.17" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
|
|
|
@ -337,13 +337,17 @@ impl Stream for WebSocket {
|
||||||
type Item = Result<Message, Error>;
|
type Item = Result<Message, Error>;
|
||||||
|
|
||||||
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
||||||
self.inner.poll_next_unpin(cx).map(|option_msg| {
|
loop {
|
||||||
option_msg.map(|result_msg| {
|
match futures_util::ready!(self.inner.poll_next_unpin(cx)) {
|
||||||
result_msg
|
Some(Ok(msg)) => {
|
||||||
.map_err(Error::new)
|
if let Some(msg) = Message::from_tungstenite(msg) {
|
||||||
.map(Message::from_tungstenite)
|
return Poll::Ready(Some(Ok(msg)));
|
||||||
})
|
}
|
||||||
})
|
}
|
||||||
|
Some(Err(err)) => return Poll::Ready(Some(Err(Error::new(err)))),
|
||||||
|
None => return Poll::Ready(None),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -444,17 +448,20 @@ impl Message {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_tungstenite(message: ts::Message) -> Self {
|
fn from_tungstenite(message: ts::Message) -> Option<Self> {
|
||||||
match message {
|
match message {
|
||||||
ts::Message::Text(text) => Self::Text(text),
|
ts::Message::Text(text) => Some(Self::Text(text)),
|
||||||
ts::Message::Binary(binary) => Self::Binary(binary),
|
ts::Message::Binary(binary) => Some(Self::Binary(binary)),
|
||||||
ts::Message::Ping(ping) => Self::Ping(ping),
|
ts::Message::Ping(ping) => Some(Self::Ping(ping)),
|
||||||
ts::Message::Pong(pong) => Self::Pong(pong),
|
ts::Message::Pong(pong) => Some(Self::Pong(pong)),
|
||||||
ts::Message::Close(Some(close)) => Self::Close(Some(CloseFrame {
|
ts::Message::Close(Some(close)) => Some(Self::Close(Some(CloseFrame {
|
||||||
code: close.code.into(),
|
code: close.code.into(),
|
||||||
reason: close.reason,
|
reason: close.reason,
|
||||||
})),
|
}))),
|
||||||
ts::Message::Close(None) => Self::Close(None),
|
ts::Message::Close(None) => Some(Self::Close(None)),
|
||||||
|
// we can ignore `Frame` frames as recommended by the tungstenite maintainers
|
||||||
|
// https://github.com/snapview/tungstenite-rs/issues/268
|
||||||
|
ts::Message::Frame(_) => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue