Skip to content

Commit

Permalink
Update to tokio-tungstenite 0.20 (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpdrsn authored Aug 2, 2023
1 parent 6a02982 commit f5dc02a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

# Unreleased

- None.
- **changed:** Update to tokio-tungstenite 0.20 ([#9])

[#9]: https://github.com/davidpdrsn/axum-tungstenite/pull/9

# 0.2.0 (10. December, 2022)

Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ repository = "https://github.com/davidpdrsn/axum-tungstenite"
[dependencies]
async-trait = "0.1.59"
axum-core = "0.3.0"
base64 = "0.20.0"
base64 = "0.21.0"
bytes = "1.3.0"
futures-util = { version = "0.3.25", default-features = false, features = ["alloc"] }
http = "0.2.8"
http-body = "0.4.5"
hyper = "0.14.23"
sha-1 = "0.10.1"
tokio = { version = "1.23.0", features = ["rt"] }
tokio-tungstenite = "0.18.0"
tokio-tungstenite = "0.20.0"

[dev-dependencies]
axum = "0.6.1"
36 changes: 31 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,33 @@ pub struct WebSocketUpgrade<F = DefaultOnFailedUpdgrade> {
}

impl<C> WebSocketUpgrade<C> {
/// Set the size of the internal message send queue.
pub fn max_send_queue(mut self, max: usize) -> Self {
self.config.max_send_queue = Some(max);
/// The target minimum size of the write buffer to reach before writing the data
/// to the underlying stream.
///
/// The default value is 128 KiB.
///
/// If set to `0` each message will be eagerly written to the underlying stream.
/// It is often more optimal to allow them to buffer a little, hence the default value.
///
/// Note: [`flush`](SinkExt::flush) will always fully write the buffer regardless.
pub fn write_buffer_size(mut self, size: usize) -> Self {
self.config.write_buffer_size = size;
self
}

/// The max size of the write buffer in bytes. Setting this can provide backpressure
/// in the case the write buffer is filling up due to write errors.
///
/// The default value is unlimited.
///
/// Note: The write buffer only builds up past [`write_buffer_size`](Self::write_buffer_size)
/// when writes to the underlying stream are failing. So the **write buffer can not
/// fill up if you are not observing write errors even if not flushing**.
///
/// Note: Should always be at least [`write_buffer_size + 1 message`](Self::write_buffer_size)
/// and probably a little more depending on error handling strategy.
pub fn max_write_buffer_size(mut self, max: usize) -> Self {
self.config.max_write_buffer_size = max;
self
}

Expand All @@ -169,7 +193,7 @@ impl<C> WebSocketUpgrade<C> {
self
}

/// Set true to accept unmasked frames from clients (defaults to false)
/// Allow server to accept unmasked frames (defaults to false)
pub fn accept_unmasked_frames(mut self, accept: bool) -> Self {
self.config.accept_unmasked_frames = accept;
self
Expand Down Expand Up @@ -437,10 +461,12 @@ impl Sink<Message> for WebSocket {
}

fn sign(key: &[u8]) -> HeaderValue {
use base64::engine::Engine as _;

let mut sha1 = Sha1::default();
sha1.update(key);
sha1.update(&b"258EAFA5-E914-47DA-95CA-C5AB0DC85B11"[..]);
let b64 = Bytes::from(base64::encode(sha1.finalize()));
let b64 = Bytes::from(base64::engine::general_purpose::STANDARD.encode(sha1.finalize()));
HeaderValue::from_maybe_shared(b64).expect("base64 is a valid value")
}

Expand Down

0 comments on commit f5dc02a

Please sign in to comment.