Skip to content

Commit

Permalink
chore!(extra): tokio-tungstenite upgrade to 0.20 (#334)
Browse files Browse the repository at this point in the history
* chore!(extra): tokio-tungstenite upgrade to 0.20

* wip
  • Loading branch information
chrislearn committed Jul 23, 2023
1 parent 186babd commit 5b43f14
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 23 deletions.
36 changes: 18 additions & 18 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = ["crates/*"]
resolver = "2"

[workspace.package]
version = "0.48.2"
version = "0.48.3"
authors = ["Chrislearn Young <[email protected]>"]
edition = "2021"
rust-version = "1.65"
Expand Down Expand Up @@ -80,23 +80,23 @@ rustls = "0.21.1"
rustls-pemfile = "1.0"
rust-embed = "6"
salvo-utils = { version = "0.0.5", default-features = true }
salvo_macros = { version = "0.48.2", path = "crates/macros", default-features = false }
salvo_core = { version = "0.48.2", path = "crates/core", default-features = false }
salvo_extra = { version = "0.48.2", path = "crates/extra", default-features = false }
salvo-compression = { version = "0.48.2", path = "crates/compression", default-features = false }
salvo-cache = { version = "0.48.2", path = "crates/cache", default-features = false }
salvo-cors = { version = "0.48.2", path = "crates/cors", default-features = false }
salvo-csrf = { version = "0.48.2", path = "crates/csrf", default-features = false }
salvo-flash = { version = "0.48.2", path = "crates/flash", default-features = false }
salvo_macros = { version = "0.48.3", path = "crates/macros", default-features = false }
salvo_core = { version = "0.48.3", path = "crates/core", default-features = false }
salvo_extra = { version = "0.48.3", path = "crates/extra", default-features = false }
salvo-compression = { version = "0.48.3", path = "crates/compression", default-features = false }
salvo-cache = { version = "0.48.3", path = "crates/cache", default-features = false }
salvo-cors = { version = "0.48.3", path = "crates/cors", default-features = false }
salvo-csrf = { version = "0.48.3", path = "crates/csrf", default-features = false }
salvo-flash = { version = "0.48.3", path = "crates/flash", default-features = false }
salvo-http3 = { version = "0.0.3", default-features = false }
salvo-jwt-auth = { version = "0.48.2", path = "crates/jwt-auth", default-features = false }
salvo-oapi = { version = "0.48.2", path = "./crates/oapi", default-features = false }
salvo-oapi-macros = { version = "0.48.2", path = "crates/oapi-macros", default-features = false }
salvo-otel = { version = "0.48.2", path = "crates/otel", default-features = false }
salvo-proxy = { version = "0.48.2", path = "crates/proxy", default-features = false }
salvo-rate-limiter = { version = "0.48.2", path = "crates/rate-limiter", default-features = false }
salvo-serve-static = { version = "0.48.2", path = "crates/serve-static", default-features = false }
salvo-session = { version = "0.48.2", path = "crates/session", default-features = false }
salvo-jwt-auth = { version = "0.48.3", path = "crates/jwt-auth", default-features = false }
salvo-oapi = { version = "0.48.3", path = "./crates/oapi", default-features = false }
salvo-oapi-macros = { version = "0.48.3", path = "crates/oapi-macros", default-features = false }
salvo-otel = { version = "0.48.3", path = "crates/otel", default-features = false }
salvo-proxy = { version = "0.48.3", path = "crates/proxy", default-features = false }
salvo-rate-limiter = { version = "0.48.3", path = "crates/rate-limiter", default-features = false }
salvo-serve-static = { version = "0.48.3", path = "crates/serve-static", default-features = false }
salvo-session = { version = "0.48.3", path = "crates/session", default-features = false }
serde = "1"
serde_json = "1"
serde-xml-rs = "0.6"
Expand All @@ -114,7 +114,7 @@ tokio-rustls = "0.24.0"
tokio-openssl = "0.6"
tokio-stream = { version = "0.1", default-features = false }
tokio-util = "0.7"
tokio-tungstenite = { version = "0.19", default-features = false }
tokio-tungstenite = { version = "0.20", default-features = false }
tracing-subscriber = { version = "0.3" }
tracing = "0.1"
tracing-test = "0.2.1"
Expand Down
48 changes: 43 additions & 5 deletions crates/extra/src/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,37 @@ impl WebSocketUpgrade {
WebSocketUpgrade { config: Some(config) }
}

/// Sets the size of the internal message send queue.
/// 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.
#[inline]
pub fn write_buffer_size(mut self, max: usize) -> Self {
self.config.get_or_insert_with(WebSocketConfig::default).write_buffer_size = max;
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.
#[inline]
pub fn max_send_queue(mut self, max: usize) -> Self {
self.config.get_or_insert_with(WebSocketConfig::default).max_send_queue = Some(max);
pub fn max_write_buffer_size(mut self, max: usize) -> Self {
self.config.get_or_insert_with(WebSocketConfig::default).max_write_buffer_size = max;
self
}

/// Sets the maximum message size (defaults to 64 megabytes)
/// The maximum size of a message. `None` means no size limit. The default value is 64 MiB
/// which should be reasonably big for all normal use-cases but small enough to prevent
/// memory eating by a malicious user.
#[inline]
pub fn max_message_size(mut self, max: usize) -> Self {
self.config
Expand All @@ -78,13 +101,28 @@ impl WebSocketUpgrade {
self
}

/// Sets the maximum frame size (defaults to 16 megabytes)
/// The maximum size of a single message frame. `None` means no size limit. The limit is for
/// frame payload NOT including the frame header. The default value is 16 MiB which should
/// be reasonably big for all normal use-cases but small enough to prevent memory eating
/// by a malicious user.
#[inline]
pub fn max_frame_size(mut self, max: usize) -> Self {
self.config.get_or_insert_with(WebSocketConfig::default).max_frame_size = Some(max);
self
}

/// When set to `true`, the server will accept and handle unmasked frames
/// from the client. According to the RFC 6455, the server must close the
/// connection to the client in such cases, however it seems like there are
/// some popular libraries that are sending unmasked frames, ignoring the RFC.
/// By default this option is set to `false`, i.e. according to RFC 6455.
#[inline]
pub fn accept_unmasked_frames(mut self, accept: bool) -> Self {
self.config.get_or_insert_with(WebSocketConfig::default).accept_unmasked_frames = accept;
self
}


/// Upgrade websocket request.
#[inline]
pub async fn upgrade<F, Fut>(&self, req: &mut Request, res: &mut Response, callback: F) -> Result<(), StatusError>
Expand Down

0 comments on commit 5b43f14

Please sign in to comment.