From 4cc8eafd3e3729bbaae2b0196a0fd5037f0dcb2c Mon Sep 17 00:00:00 2001 From: Igor Aleksanov Date: Tue, 22 Jun 2021 19:49:39 +0300 Subject: [PATCH] Various fixes in actix-http crate --- actix-http/benches/uninit-headers.rs | 6 ++-- actix-http/src/body/body.rs | 1 + actix-http/src/builder.rs | 1 + actix-http/src/client/connector.rs | 9 +++--- actix-http/src/client/h2proto.rs | 13 ++++----- actix-http/src/config.rs | 18 +++++++++--- actix-http/src/error.rs | 2 +- actix-http/src/extensions.rs | 3 ++ actix-http/src/h1/client.rs | 7 +++++ actix-http/src/h1/codec.rs | 6 ++++ actix-http/src/h1/decoder.rs | 6 ++-- actix-http/src/h1/dispatcher.rs | 5 ++-- actix-http/src/h1/payload.rs | 8 ++--- actix-http/src/header/map.rs | 14 +++++++-- .../src/header/shared/content_encoding.rs | 3 ++ actix-http/src/message.rs | 29 ++++++++++--------- actix-http/src/request.rs | 1 + actix-http/src/response.rs | 6 ++++ actix-http/src/response_builder.rs | 2 ++ actix-http/src/service.rs | 1 + actix-http/src/ws/codec.rs | 3 ++ actix-http/src/ws/frame.rs | 1 + actix-http/src/ws/proto.rs | 1 + 23 files changed, 100 insertions(+), 46 deletions(-) diff --git a/actix-http/benches/uninit-headers.rs b/actix-http/benches/uninit-headers.rs index 83e74171c..53a2528ab 100644 --- a/actix-http/benches/uninit-headers.rs +++ b/actix-http/benches/uninit-headers.rs @@ -78,12 +78,12 @@ impl HeaderIndex { // test cases taken from: // https://github.com/seanmonstar/httparse/blob/master/benches/parse.rs -const REQ_SHORT: &'static [u8] = b"\ +const REQ_SHORT: &[u8] = b"\ GET / HTTP/1.0\r\n\ Host: example.com\r\n\ Cookie: session=60; user_id=1\r\n\r\n"; -const REQ: &'static [u8] = b"\ +const REQ: &[u8] = b"\ GET /wp-content/uploads/2010/03/hello-kitty-darth-vader-pink.jpg HTTP/1.1\r\n\ Host: www.kittyhell.com\r\n\ User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; ja-JP-mac; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 Pathtraq/0.9\r\n\ @@ -119,6 +119,8 @@ mod _original { use std::mem::MaybeUninit; pub fn parse_headers(src: &mut BytesMut) -> usize { + #![allow(clippy::uninit_assumed_init)] + let mut headers: [HeaderIndex; MAX_HEADERS] = unsafe { MaybeUninit::uninit().assume_init() }; diff --git a/actix-http/src/body/body.rs b/actix-http/src/body/body.rs index f04837d07..9c5934e9a 100644 --- a/actix-http/src/body/body.rs +++ b/actix-http/src/body/body.rs @@ -32,6 +32,7 @@ pub enum AnyBody { impl AnyBody { /// Create body from slice (copy) + #[must_use] pub fn from_slice(s: &[u8]) -> Self { Self::Bytes(Bytes::copy_from_slice(s)) } diff --git a/actix-http/src/builder.rs b/actix-http/src/builder.rs index 4e68dc920..724077358 100644 --- a/actix-http/src/builder.rs +++ b/actix-http/src/builder.rs @@ -36,6 +36,7 @@ where >::Future: 'static, { /// Create instance of `ServiceConfigBuilder` + #[must_use] pub fn new() -> Self { HttpServiceBuilder { keep_alive: KeepAlive::Timeout(5), diff --git a/actix-http/src/client/connector.rs b/actix-http/src/client/connector.rs index 508fe748b..187a72138 100644 --- a/actix-http/src/client/connector.rs +++ b/actix-http/src/client/connector.rs @@ -64,6 +64,7 @@ pub struct Connector { impl Connector<()> { #[allow(clippy::new_ret_no_self, clippy::let_unit_value)] + #[must_use] pub fn new() -> Connector< impl Service< TcpConnect, @@ -85,7 +86,7 @@ impl Connector<()> { use bytes::{BufMut, BytesMut}; let mut alpn = BytesMut::with_capacity(20); - for proto in protocols.iter() { + for proto in &protocols { alpn.put_u8(proto.len() as u8); alpn.put(proto.as_slice()); } @@ -290,8 +291,7 @@ where let h2 = sock .ssl() .selected_alpn_protocol() - .map(|protos| protos.windows(2).any(|w| w == H2)) - .unwrap_or(false); + .map_or(false, |protos| protos.windows(2).any(|w| w == H2)); if h2 { (Box::new(sock), Protocol::Http2) } else { @@ -325,8 +325,7 @@ where .get_ref() .1 .get_alpn_protocol() - .map(|protos| protos.windows(2).any(|w| w == H2)) - .unwrap_or(false); + .map_or(false, |protos| protos.windows(2).any(|w| w == H2)); if h2 { (Box::new(sock), Protocol::Http2) } else { diff --git a/actix-http/src/client/h2proto.rs b/actix-http/src/client/h2proto.rs index cf423ef12..b9d5f96bd 100644 --- a/actix-http/src/client/h2proto.rs +++ b/actix-http/src/client/h2proto.rs @@ -168,14 +168,13 @@ where if let Err(e) = send.send_data(bytes, false) { return Err(e.into()); - } else { - if !b.is_empty() { - send.reserve_capacity(b.len()); - } else { - buf = None; - } - continue; } + if !b.is_empty() { + send.reserve_capacity(b.len()); + } else { + buf = None; + } + continue; } Some(Err(e)) => return Err(e.into()), } diff --git a/actix-http/src/config.rs b/actix-http/src/config.rs index 9a2293e92..bc934b50e 100644 --- a/actix-http/src/config.rs +++ b/actix-http/src/config.rs @@ -68,6 +68,7 @@ impl Default for ServiceConfig { impl ServiceConfig { /// Create instance of `ServiceConfig` + #[must_use] pub fn new( keep_alive: KeepAlive, client_timeout: u64, @@ -99,30 +100,35 @@ impl ServiceConfig { /// Returns true if connection is secure (HTTPS) #[inline] + #[must_use] pub fn secure(&self) -> bool { self.0.secure } /// Returns the local address that this server is bound to. #[inline] + #[must_use] pub fn local_addr(&self) -> Option { self.0.local_addr } /// Keep alive duration if configured. #[inline] + #[must_use] pub fn keep_alive(&self) -> Option { self.0.keep_alive } /// Return state of connection keep-alive functionality #[inline] + #[must_use] pub fn keep_alive_enabled(&self) -> bool { self.0.ka_enabled } /// Client timeout for first request. #[inline] + #[must_use] pub fn client_timer(&self) -> Option { let delay_time = self.0.client_timeout; if delay_time != 0 { @@ -133,6 +139,7 @@ impl ServiceConfig { } /// Client timeout for first request. + #[must_use] pub fn client_timer_expire(&self) -> Option { let delay = self.0.client_timeout; if delay != 0 { @@ -143,6 +150,7 @@ impl ServiceConfig { } /// Client disconnect timer + #[must_use] pub fn client_disconnect_timer(&self) -> Option { let delay = self.0.client_disconnect; if delay != 0 { @@ -152,13 +160,15 @@ impl ServiceConfig { } } - #[inline] /// Return keep-alive timer delay is configured. + #[inline] + #[must_use] pub fn keep_alive_timer(&self) -> Option { self.keep_alive().map(|ka| sleep_until(self.now() + ka)) } /// Keep-alive expire time + #[must_use] pub fn keep_alive_expire(&self) -> Option { self.keep_alive().map(|ka| self.now() + ka) } @@ -365,11 +375,11 @@ mod tests { let clone3 = service.clone(); drop(clone1); - assert_eq!(false, notify_on_drop::is_dropped()); + assert!(!notify_on_drop::is_dropped()); drop(clone2); - assert_eq!(false, notify_on_drop::is_dropped()); + assert!(!notify_on_drop::is_dropped()); drop(clone3); - assert_eq!(false, notify_on_drop::is_dropped()); + assert!(!notify_on_drop::is_dropped()); drop(service); assert!(notify_on_drop::is_dropped()); diff --git a/actix-http/src/error.rs b/actix-http/src/error.rs index d9e1a1ed2..6c3d692c3 100644 --- a/actix-http/src/error.rs +++ b/actix-http/src/error.rs @@ -125,7 +125,7 @@ impl fmt::Display for Error { impl StdError for Error { fn source(&self) -> Option<&(dyn StdError + 'static)> { - self.inner.cause.as_ref().map(|err| err.as_ref()) + self.inner.cause.as_ref().map(Box::as_ref) } } diff --git a/actix-http/src/extensions.rs b/actix-http/src/extensions.rs index 5fdcefd6d..991e41258 100644 --- a/actix-http/src/extensions.rs +++ b/actix-http/src/extensions.rs @@ -18,6 +18,7 @@ pub struct Extensions { impl Extensions { /// Creates an empty `Extensions`. #[inline] + #[must_use] pub fn new() -> Extensions { Extensions { map: AHashMap::default(), @@ -52,6 +53,7 @@ impl Extensions { /// assert_eq!(map.insert(1u32), None); /// assert!(map.contains::()); /// ``` + #[must_use] pub fn contains(&self) -> bool { self.map.contains_key(&TypeId::of::()) } @@ -64,6 +66,7 @@ impl Extensions { /// map.insert(1u32); /// assert_eq!(map.get::(), Some(&1u32)); /// ``` + #[must_use] pub fn get(&self) -> Option<&T> { self.map .get(&TypeId::of::()) diff --git a/actix-http/src/h1/client.rs b/actix-http/src/h1/client.rs index 4a6104688..325764404 100644 --- a/actix-http/src/h1/client.rs +++ b/actix-http/src/h1/client.rs @@ -53,6 +53,7 @@ impl ClientCodec { /// Create HTTP/1 codec. /// /// `keepalive_enabled` how response `connection` header get generated. + #[must_use] pub fn new(config: ServiceConfig) -> Self { let flags = if config.keep_alive_enabled() { Flags::KEEPALIVE_ENABLED @@ -74,16 +75,19 @@ impl ClientCodec { } /// Check if request is upgrade + #[must_use] pub fn upgrade(&self) -> bool { self.inner.ctype == ConnectionType::Upgrade } /// Check if last response is keep-alive + #[must_use] pub fn keepalive(&self) -> bool { self.inner.ctype == ConnectionType::KeepAlive } /// Check last request's message type + #[must_use] pub fn message_type(&self) -> MessageType { if self.inner.flags.contains(Flags::STREAM) { MessageType::Stream @@ -95,6 +99,7 @@ impl ClientCodec { } /// Convert message codec to a payload codec + #[must_use] pub fn into_payload_codec(self) -> ClientPayloadCodec { ClientPayloadCodec { inner: self.inner } } @@ -102,11 +107,13 @@ impl ClientCodec { impl ClientPayloadCodec { /// Check if last response is keep-alive + #[must_use] pub fn keepalive(&self) -> bool { self.inner.ctype == ConnectionType::KeepAlive } /// Transform payload codec to a message codec + #[must_use] pub fn into_message_codec(self) -> ClientCodec { ClientCodec { inner: self.inner } } diff --git a/actix-http/src/h1/codec.rs b/actix-http/src/h1/codec.rs index 634ca25e8..db221a7f0 100644 --- a/actix-http/src/h1/codec.rs +++ b/actix-http/src/h1/codec.rs @@ -52,6 +52,7 @@ impl Codec { /// Create HTTP/1 codec. /// /// `keepalive_enabled` how response `connection` header get generated. + #[must_use] pub fn new(config: ServiceConfig) -> Self { let flags = if config.keep_alive_enabled() { Flags::KEEPALIVE_ENABLED @@ -72,24 +73,28 @@ impl Codec { /// Check if request is upgrade. #[inline] + #[must_use] pub fn upgrade(&self) -> bool { self.ctype == ConnectionType::Upgrade } /// Check if last response is keep-alive. #[inline] + #[must_use] pub fn keepalive(&self) -> bool { self.ctype == ConnectionType::KeepAlive } /// Check if keep-alive enabled on server level. #[inline] + #[must_use] pub fn keepalive_enabled(&self) -> bool { self.flags.contains(Flags::KEEPALIVE_ENABLED) } /// Check last request's message type. #[inline] + #[must_use] pub fn message_type(&self) -> MessageType { if self.flags.contains(Flags::STREAM) { MessageType::Stream @@ -101,6 +106,7 @@ impl Codec { } #[inline] + #[must_use] pub fn config(&self) -> &ServiceConfig { &self.config } diff --git a/actix-http/src/h1/decoder.rs b/actix-http/src/h1/decoder.rs index 8aba9f623..f240710c2 100644 --- a/actix-http/src/h1/decoder.rs +++ b/actix-http/src/h1/decoder.rs @@ -102,7 +102,7 @@ pub(crate) trait MessageType: Sized { } // transfer-encoding header::TRANSFER_ENCODING => { - if let Ok(s) = value.to_str().map(|s| s.trim()) { + if let Ok(s) = value.to_str().map(str::trim) { chunked = s.eq_ignore_ascii_case("chunked"); } else { return Err(ParseError::Header); @@ -110,7 +110,7 @@ pub(crate) trait MessageType: Sized { } // connection keep-alive state header::CONNECTION => { - ka = if let Ok(conn) = value.to_str().map(|conn| conn.trim()) { + ka = if let Ok(conn) = value.to_str().map(str::trim) { if conn.eq_ignore_ascii_case("keep-alive") { Some(ConnectionType::KeepAlive) } else if conn.eq_ignore_ascii_case("close") { @@ -125,7 +125,7 @@ pub(crate) trait MessageType: Sized { }; } header::UPGRADE => { - if let Ok(val) = value.to_str().map(|val| val.trim()) { + if let Ok(val) = value.to_str().map(str::trim) { if val.eq_ignore_ascii_case("websocket") { has_upgrade_websocket = true; } diff --git a/actix-http/src/h1/dispatcher.rs b/actix-http/src/h1/dispatcher.rs index b4adde638..6b4b32090 100644 --- a/actix-http/src/h1/dispatcher.rs +++ b/actix-http/src/h1/dispatcher.rs @@ -515,14 +515,13 @@ where cx: &mut Context<'_>, ) -> Result<(), DispatchError> { // Handle `EXPECT: 100-Continue` header + // set dispatcher state so the future is pinned. + let mut this = self.as_mut().project(); if req.head().expect() { - // set dispatcher state so the future is pinned. - let mut this = self.as_mut().project(); let task = this.flow.expect.call(req); this.state.set(State::ExpectCall(task)); } else { // the same as above. - let mut this = self.as_mut().project(); let task = this.flow.service.call(req); this.state.set(State::ServiceCall(task)); }; diff --git a/actix-http/src/h1/payload.rs b/actix-http/src/h1/payload.rs index e72493fa2..24f6283fe 100644 --- a/actix-http/src/h1/payload.rs +++ b/actix-http/src/h1/payload.rs @@ -41,6 +41,7 @@ impl Payload { /// * `PayloadSender` - *Sender* side of the stream /// /// * `Payload` - *Receiver* side of the stream + #[must_use] pub fn create(eof: bool) -> (PayloadSender, Payload) { let shared = Rc::new(RefCell::new(Inner::new(eof))); @@ -54,6 +55,7 @@ impl Payload { /// Create empty payload #[doc(hidden)] + #[must_use] pub fn empty() -> Payload { Payload { inner: Rc::new(RefCell::new(Inner::new(true))), @@ -186,8 +188,7 @@ impl Inner { if self .task .as_ref() - .map(|w| !cx.waker().will_wake(w)) - .unwrap_or(true) + .map_or(true, |w| !cx.waker().will_wake(w)) { self.task = Some(cx.waker().clone()); } @@ -199,8 +200,7 @@ impl Inner { if self .io_task .as_ref() - .map(|w| !cx.waker().will_wake(w)) - .unwrap_or(true) + .map_or(true, |w| !cx.waker().will_wake(w)) { self.io_task = Some(cx.waker().clone()); } diff --git a/actix-http/src/header/map.rs b/actix-http/src/header/map.rs index be33ec02a..eabc2d277 100644 --- a/actix-http/src/header/map.rs +++ b/actix-http/src/header/map.rs @@ -81,6 +81,7 @@ impl HeaderMap { /// assert!(map.is_empty()); /// assert_eq!(0, map.capacity()); /// ``` + #[must_use] pub fn new() -> Self { HeaderMap::default() } @@ -98,6 +99,7 @@ impl HeaderMap { /// assert!(map.is_empty()); /// assert!(map.capacity() >= 16); /// ``` + #[must_use] pub fn with_capacity(capacity: usize) -> Self { HeaderMap { inner: AHashMap::with_capacity(capacity), @@ -150,6 +152,7 @@ impl HeaderMap { /// map.append(header::SET_COOKIE, HeaderValue::from_static("two=2")); /// assert_eq!(map.len(), 3); /// ``` + #[must_use] pub fn len(&self) -> usize { self.inner .iter() @@ -173,6 +176,7 @@ impl HeaderMap { /// map.append(header::SET_COOKIE, HeaderValue::from_static("two=2")); /// assert_eq!(map.len_keys(), 2); /// ``` + #[must_use] pub fn len_keys(&self) -> usize { self.inner.len() } @@ -188,6 +192,7 @@ impl HeaderMap { /// map.insert(header::ACCEPT, HeaderValue::from_static("text/plain")); /// assert!(!map.is_empty()); /// ``` + #[must_use] pub fn is_empty(&self) -> bool { self.inner.len() == 0 } @@ -249,7 +254,7 @@ impl HeaderMap { /// assert!(map.get("INVALID HEADER NAME").is_none()); /// ``` pub fn get(&self, key: impl AsHeaderName) -> Option<&HeaderValue> { - self.get_value(key).map(|val| val.first()) + self.get_value(key).map(Value::first) } /// Returns a mutable reference to the _first_ value associated a header name. @@ -280,8 +285,8 @@ impl HeaderMap { /// ``` pub fn get_mut(&mut self, key: impl AsHeaderName) -> Option<&mut HeaderValue> { match key.try_as_name(super::as_name::Seal).ok()? { - Cow::Borrowed(name) => self.inner.get_mut(name).map(|v| v.first_mut()), - Cow::Owned(name) => self.inner.get_mut(&name).map(|v| v.first_mut()), + Cow::Borrowed(name) => self.inner.get_mut(name).map(Value::first_mut), + Cow::Owned(name) => self.inner.get_mut(&name).map(Value::first_mut), } } @@ -434,6 +439,7 @@ impl HeaderMap { /// assert!(map.is_empty()); /// assert!(map.capacity() >= 16); /// ``` + #[must_use] pub fn capacity(&self) -> usize { self.inner.capacity() } @@ -489,6 +495,7 @@ impl HeaderMap { /// assert!(pairs.contains(&(&header::SET_COOKIE, &HeaderValue::from_static("one=1")))); /// assert!(pairs.contains(&(&header::SET_COOKIE, &HeaderValue::from_static("two=2")))); /// ``` + #[must_use] pub fn iter(&self) -> Iter<'_> { Iter::new(self.inner.iter()) } @@ -515,6 +522,7 @@ impl HeaderMap { /// assert!(keys.contains(&header::HOST)); /// assert!(keys.contains(&header::SET_COOKIE)); /// ``` + #[must_use] pub fn keys(&self) -> Keys<'_> { Keys(self.inner.keys()) } diff --git a/actix-http/src/header/shared/content_encoding.rs b/actix-http/src/header/shared/content_encoding.rs index b9c1d2795..8e1c78144 100644 --- a/actix-http/src/header/shared/content_encoding.rs +++ b/actix-http/src/header/shared/content_encoding.rs @@ -33,12 +33,14 @@ pub enum ContentEncoding { impl ContentEncoding { /// Is the content compressed? #[inline] + #[must_use] pub fn is_compression(self) -> bool { matches!(self, ContentEncoding::Identity | ContentEncoding::Auto) } /// Convert content encoding to string #[inline] + #[must_use] pub fn as_str(self) -> &'static str { match self { ContentEncoding::Br => "br", @@ -51,6 +53,7 @@ impl ContentEncoding { /// Default Q-factor (quality) value. #[inline] + #[must_use] pub fn quality(self) -> f64 { match self { ContentEncoding::Br => 1.1, diff --git a/actix-http/src/message.rs b/actix-http/src/message.rs index 0a3f3a915..6712a4b13 100644 --- a/actix-http/src/message.rs +++ b/actix-http/src/message.rs @@ -152,15 +152,16 @@ impl RequestHead { /// Connection upgrade status pub fn upgrade(&self) -> bool { - if let Some(hdr) = self.headers().get(header::CONNECTION) { - if let Ok(s) = hdr.to_str() { - s.to_ascii_lowercase().contains("upgrade") - } else { - false - } - } else { - false - } + self.headers() + .get(header::CONNECTION) + .map(|hdr| { + if let Ok(s) = hdr.to_str() { + s.to_ascii_lowercase().contains("upgrade") + } else { + false + } + }) + .unwrap_or(false) } #[inline] @@ -233,6 +234,7 @@ pub struct ResponseHead { impl ResponseHead { /// Create new instance of `ResponseHead` type #[inline] + #[must_use] pub fn new(status: StatusCode) -> ResponseHead { ResponseHead { status, @@ -308,13 +310,11 @@ impl ResponseHead { /// Get custom reason for the response #[inline] pub fn reason(&self) -> &str { - if let Some(reason) = self.reason { - reason - } else { + self.reason.unwrap_or_else(|| { self.status .canonical_reason() .unwrap_or("") - } + }) } #[inline] @@ -355,8 +355,9 @@ pub struct Message { impl Message { /// Get new message from the pool of objects + #[must_use] pub fn new() -> Self { - T::with_pool(|p| p.get_message()) + T::with_pool(MessagePool::get_message) } } diff --git a/actix-http/src/request.rs b/actix-http/src/request.rs index 09c6dd296..7ac0da200 100644 --- a/actix-http/src/request.rs +++ b/actix-http/src/request.rs @@ -57,6 +57,7 @@ impl From> for Request { impl Request { /// Create new Request instance + #[must_use] pub fn new() -> Request { Request { head: Message::new(), diff --git a/actix-http/src/response.rs b/actix-http/src/response.rs index 2aa38c153..1d105cff4 100644 --- a/actix-http/src/response.rs +++ b/actix-http/src/response.rs @@ -25,6 +25,7 @@ pub struct Response { impl Response { /// Constructs a new response with default body. #[inline] + #[must_use] pub fn new(status: StatusCode) -> Self { Response { head: BoxedResponseHead::new(status), @@ -34,6 +35,7 @@ impl Response { /// Constructs a new response builder. #[inline] + #[must_use] pub fn build(status: StatusCode) -> ResponseBuilder { ResponseBuilder::new(status) } @@ -43,24 +45,28 @@ impl Response { /// Constructs a new response with status 200 OK. #[inline] + #[must_use] pub fn ok() -> Self { Response::new(StatusCode::OK) } /// Constructs a new response with status 400 Bad Request. #[inline] + #[must_use] pub fn bad_request() -> Self { Response::new(StatusCode::BAD_REQUEST) } /// Constructs a new response with status 404 Not Found. #[inline] + #[must_use] pub fn not_found() -> Self { Response::new(StatusCode::NOT_FOUND) } /// Constructs a new response with status 500 Internal Server Error. #[inline] + #[must_use] pub fn internal_server_error() -> Self { Response::new(StatusCode::INTERNAL_SERVER_ERROR) } diff --git a/actix-http/src/response_builder.rs b/actix-http/src/response_builder.rs index e46d9a28c..124b5864d 100644 --- a/actix-http/src/response_builder.rs +++ b/actix-http/src/response_builder.rs @@ -62,6 +62,7 @@ impl ResponseBuilder { /// assert_eq!(res.status(), StatusCode::OK); /// ``` #[inline] + #[must_use] pub fn new(status: StatusCode) -> Self { ResponseBuilder { head: Some(BoxedResponseHead::new(status)), @@ -220,6 +221,7 @@ impl ResponseBuilder { /// Responses extensions #[inline] + #[must_use] pub fn extensions(&self) -> Ref<'_, Extensions> { let head = self.head.as_ref().expect("cannot reuse response builder"); head.extensions.borrow() diff --git a/actix-http/src/service.rs b/actix-http/src/service.rs index afe47bf2d..13a00b61d 100644 --- a/actix-http/src/service.rs +++ b/actix-http/src/service.rs @@ -47,6 +47,7 @@ where B: MessageBody + 'static, { /// Create builder for `HttpService` instance. + #[must_use] pub fn build() -> HttpServiceBuilder { HttpServiceBuilder::new() } diff --git a/actix-http/src/ws/codec.rs b/actix-http/src/ws/codec.rs index 8655216fa..ab1a50695 100644 --- a/actix-http/src/ws/codec.rs +++ b/actix-http/src/ws/codec.rs @@ -80,6 +80,7 @@ bitflags! { impl Codec { /// Create new WebSocket frames decoder. + #[must_use] pub const fn new() -> Codec { Codec { max_size: 65_536, @@ -90,6 +91,7 @@ impl Codec { /// Set max frame size. /// /// By default max size is set to 64kB. + #[must_use] pub fn max_size(mut self, size: usize) -> Self { self.max_size = size; self @@ -98,6 +100,7 @@ impl Codec { /// Set decoder to client mode. /// /// By default decoder works in server mode. + #[must_use] pub fn client_mode(mut self) -> Self { self.flags.remove(Flags::SERVER); self diff --git a/actix-http/src/ws/frame.rs b/actix-http/src/ws/frame.rs index 46edf5d85..3e9d302ea 100644 --- a/actix-http/src/ws/frame.rs +++ b/actix-http/src/ws/frame.rs @@ -139,6 +139,7 @@ impl Parser { } /// Parse the payload of a close frame. + #[must_use] pub fn parse_close_payload(payload: &[u8]) -> Option { if payload.len() >= 2 { let raw_code = u16::from_be_bytes(TryFrom::try_from(&payload[..2]).unwrap()); diff --git a/actix-http/src/ws/proto.rs b/actix-http/src/ws/proto.rs index fdcde5eac..137485c45 100644 --- a/actix-http/src/ws/proto.rs +++ b/actix-http/src/ws/proto.rs @@ -226,6 +226,7 @@ static WS_GUID: &[u8] = b"258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; /// Hashes the `Sec-WebSocket-Key` header according to the WebSocket spec. /// /// Result is a Base64 encoded byte array. `base64(sha1(input))` is always 28 bytes. +#[must_use] pub fn hash_key(key: &[u8]) -> [u8; 28] { let hash = { use sha1::Digest as _;