From 09dfb88722a9dad2f86cd2d4a21bc3bd19ce6c1d Mon Sep 17 00:00:00 2001 From: LucaCappelletti94 Date: Fri, 14 Feb 2025 13:37:47 +0100 Subject: [PATCH] Added serde derive to close reason and close code --- actix-http/Cargo.toml | 3 +++ actix-http/src/ws/proto.rs | 2 ++ 2 files changed, 5 insertions(+) diff --git a/actix-http/Cargo.toml b/actix-http/Cargo.toml index a1b73517..6f13bb18 100644 --- a/actix-http/Cargo.toml +++ b/actix-http/Cargo.toml @@ -69,6 +69,8 @@ ws = [ "dep:sha1", ] +serde = ["dep:serde"] + # TLS via OpenSSL openssl = ["__tls", "actix-tls/accept", "actix-tls/openssl"] @@ -121,6 +123,7 @@ language-tags = "0.3" mime = "0.3.4" percent-encoding = "2.1" pin-project-lite = "0.2" +serde = { version = "1", features = ["derive"], optional = true } smallvec = "1.6.1" tokio = { version = "1.24.2", features = [] } tokio-util = { version = "0.7", features = ["io", "codec"] } diff --git a/actix-http/src/ws/proto.rs b/actix-http/src/ws/proto.rs index 27815eaf..10fc1c5b 100644 --- a/actix-http/src/ws/proto.rs +++ b/actix-http/src/ws/proto.rs @@ -83,6 +83,7 @@ impl From for OpCode { /// Status code used to indicate why an endpoint is closing the WebSocket connection. #[derive(Debug, Eq, PartialEq, Clone, Copy)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum CloseCode { /// Indicates a normal closure, meaning that the purpose for which the connection was /// established has been fulfilled. @@ -195,6 +196,7 @@ impl From for CloseCode { } #[derive(Debug, Eq, PartialEq, Clone)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] /// Reason for closing the connection pub struct CloseReason { /// Exit code