From 5c99403abddc618281f981d10b6a23b94ee75f92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20F=C3=A9ron?= Date: Thu, 17 Oct 2024 23:09:43 +0200 Subject: [PATCH] Introduce trait to share error handling between PushService and WebSocketService --- src/account_manager.rs | 16 ++- src/groups_v2/manager.rs | 4 +- src/profile_service.rs | 4 +- src/push_service/account.rs | 16 ++- src/push_service/cdn.rs | 14 ++- src/push_service/error.rs | 4 +- src/push_service/keys.rs | 30 +++-- src/push_service/linking.rs | 12 +- src/push_service/mod.rs | 199 +++++++++---------------------- src/push_service/profile.rs | 4 +- src/push_service/registration.rs | 22 +++- src/push_service/response.rs | 160 +++++++++++++++++++++++++ src/websocket/mod.rs | 97 ++------------- src/websocket/sender.rs | 5 +- 14 files changed, 319 insertions(+), 268 deletions(-) create mode 100644 src/push_service/response.rs diff --git a/src/account_manager.rs b/src/account_manager.rs index 84ade2573..f3d4301ee 100644 --- a/src/account_manager.rs +++ b/src/account_manager.rs @@ -229,7 +229,9 @@ impl AccountManager { "/v1/devices/provisioning/code", HttpAuthOverride::NoOverride, )? - .send_to_signal() + .send() + .await? + .service_error_for_status() .await? .json() .await?; @@ -259,7 +261,9 @@ impl AccountManager { .json(&ProvisioningMessage { body: BASE64_RELAXED.encode(body), }) - .send_to_signal() + .send() + .await? + .service_error_for_status() .await?; Ok(()) @@ -597,7 +601,9 @@ impl AccountManager { .json(&Data { device_name: encrypted_device_name.encode_to_vec(), }) - .send_to_signal() + .send() + .await? + .service_error_for_status() .await?; Ok(()) @@ -626,7 +632,9 @@ impl AccountManager { token: String::from(token), captcha: String::from(captcha), }) - .send_to_signal() + .send() + .await? + .service_error_for_status() .await?; Ok(()) diff --git a/src/groups_v2/manager.rs b/src/groups_v2/manager.rs index 9183bef10..93e6229c7 100644 --- a/src/groups_v2/manager.rs +++ b/src/groups_v2/manager.rs @@ -174,7 +174,9 @@ impl GroupsManager { &path, HttpAuthOverride::NoOverride, )? - .send_to_signal() + .send() + .await? + .service_error_for_status() .await? .json() .await?; diff --git a/src/profile_service.rs b/src/profile_service.rs index 0c02b12ba..016658876 100644 --- a/src/profile_service.rs +++ b/src/profile_service.rs @@ -45,7 +45,9 @@ impl ProfileService { path, HttpAuthOverride::NoOverride, )? - .send_to_signal() + .send() + .await? + .service_error_for_status() .await? .json() .await diff --git a/src/push_service/account.rs b/src/push_service/account.rs index 293e0857e..0cc99ea0b 100644 --- a/src/push_service/account.rs +++ b/src/push_service/account.rs @@ -6,7 +6,9 @@ use reqwest::Method; use serde::{Deserialize, Serialize}; use uuid::Uuid; -use super::{HttpAuthOverride, PushService, ReqwestExt, ServiceError}; +use super::{ + response::ReqwestExt, HttpAuthOverride, PushService, ServiceError, +}; use crate::{ configuration::Endpoint, utils::{serde_optional_base64, serde_phone_number}, @@ -134,7 +136,9 @@ impl PushService { "/v1/accounts/whoami", HttpAuthOverride::NoOverride, )? - .send_to_signal() + .send() + .await? + .service_error_for_status() .await? .json() .await @@ -157,7 +161,9 @@ impl PushService { "/v1/devices/", HttpAuthOverride::NoOverride, )? - .send_to_signal() + .send() + .await? + .service_error_for_status() .await? .json() .await?; @@ -181,7 +187,9 @@ impl PushService { HttpAuthOverride::NoOverride, )? .json(&attributes) - .send_to_signal() + .send() + .await? + .service_error_for_status() .await? .json() .await diff --git a/src/push_service/cdn.rs b/src/push_service/cdn.rs index 8309807b2..a345b563e 100644 --- a/src/push_service/cdn.rs +++ b/src/push_service/cdn.rs @@ -9,7 +9,7 @@ use crate::{ proto::AttachmentPointer, push_service::HttpAuthOverride, }; -use super::{PushService, ReqwestExt, ServiceError}; +use super::{response::ReqwestExt, PushService, ServiceError}; #[derive(Debug, serde::Deserialize, Default)] #[serde(rename_all = "camelCase")] @@ -53,7 +53,9 @@ impl PushService { path, HttpAuthOverride::Unidentified, // CDN requests are always without authentication )? - .send_to_signal() + .send() + .await? + .service_error_for_status() .await? .bytes_stream() .map_err(|e| io::Error::new(io::ErrorKind::Other, e)) @@ -71,7 +73,9 @@ impl PushService { "/v2/attachments/form/upload", HttpAuthOverride::NoOverride, )? - .send_to_signal() + .send() + .await? + .service_error_for_status() .await? .json() .await @@ -130,7 +134,9 @@ impl PushService { HttpAuthOverride::NoOverride, )? .multipart(form) - .send_to_signal() + .send() + .await? + .service_error_for_status() .await?; debug!("HyperPushService::PUT response: {:?}", response); diff --git a/src/push_service/error.rs b/src/push_service/error.rs index 2e96f27c7..99561c9e7 100644 --- a/src/push_service/error.rs +++ b/src/push_service/error.rs @@ -21,8 +21,8 @@ pub enum ServiceError { #[error("Error decoding response: {reason}")] ResponseError { reason: String }, - #[error("Error decoding JSON response: {reason}")] - JsonDecodeError { reason: String }, + #[error("Error decoding JSON: {0}")] + JsonDecodeError(#[from] serde_json::Error), #[error("Error decoding protobuf frame: {0}")] ProtobufDecodeError(#[from] prost::DecodeError), #[error("error encoding or decoding bincode: {0}")] diff --git a/src/push_service/keys.rs b/src/push_service/keys.rs index 93b7d6636..df5892313 100644 --- a/src/push_service/keys.rs +++ b/src/push_service/keys.rs @@ -14,7 +14,7 @@ use crate::{ }; use super::{ - HttpAuthOverride, PushService, ReqwestExt, SenderCertificateJson, + response::ReqwestExt, HttpAuthOverride, PushService, SenderCertificateJson, ServiceError, ServiceIdType, VerifyAccountResponse, }; @@ -36,7 +36,9 @@ impl PushService { &format!("/v2/keys?identity={}", service_id_type), HttpAuthOverride::NoOverride, )? - .send_to_signal() + .send() + .await? + .service_error_for_status() .await? .json() .await @@ -55,7 +57,9 @@ impl PushService { HttpAuthOverride::NoOverride, )? .json(&pre_key_state) - .send_to_signal() + .send() + .await? + .service_error_for_status() .await?; Ok(()) @@ -76,7 +80,9 @@ impl PushService { &path, HttpAuthOverride::NoOverride, )? - .send_to_signal() + .send() + .await? + .service_error_for_status() .await? .json() .await?; @@ -105,7 +111,9 @@ impl PushService { &path, HttpAuthOverride::NoOverride, )? - .send_to_signal() + .send() + .await? + .service_error_for_status() .await? .json() .await?; @@ -127,7 +135,9 @@ impl PushService { "/v1/certificate/delivery", HttpAuthOverride::NoOverride, )? - .send_to_signal() + .send() + .await? + .service_error_for_status() .await? .json() .await?; @@ -144,7 +154,9 @@ impl PushService { "/v1/certificate/delivery?includeE164=false", HttpAuthOverride::NoOverride, )? - .send_to_signal() + .send() + .await? + .service_error_for_status() .await? .json() .await?; @@ -190,7 +202,9 @@ impl PushService { pni_registration_ids, signature_valid_on_each_signed_pre_key, }) - .send_to_signal() + .send() + .await? + .service_error_for_status() .await? .json() .await diff --git a/src/push_service/linking.rs b/src/push_service/linking.rs index d10f20116..5d5026c6c 100644 --- a/src/push_service/linking.rs +++ b/src/push_service/linking.rs @@ -5,8 +5,8 @@ use uuid::Uuid; use crate::configuration::Endpoint; use super::{ - DeviceActivationRequest, HttpAuth, HttpAuthOverride, PushService, - ReqwestExt, ServiceError, + response::ReqwestExt, DeviceActivationRequest, HttpAuth, HttpAuthOverride, + PushService, ServiceError, }; #[derive(Debug, Serialize)] @@ -67,7 +67,9 @@ impl PushService { HttpAuthOverride::Identified(http_auth), )? .json(&link_request) - .send_to_signal() + .send() + .await? + .service_error_for_status() .await? .json() .await @@ -81,7 +83,9 @@ impl PushService { format!("/v1/devices/{}", id), HttpAuthOverride::NoOverride, )? - .send_to_signal() + .send() + .await? + .service_error_for_status() .await?; Ok(()) diff --git a/src/push_service/mod.rs b/src/push_service/mod.rs index daf683617..b4e52aabc 100644 --- a/src/push_service/mod.rs +++ b/src/push_service/mod.rs @@ -15,7 +15,7 @@ use libsignal_protocol::{ IdentityKey, PreKeyBundle, PublicKey, }; use protobuf::ProtobufResponseExt; -use reqwest::{Method, RequestBuilder, Response, StatusCode}; +use reqwest::{Method, RequestBuilder}; use reqwest_websocket::RequestBuilderExt; use serde::{Deserialize, Serialize}; use tracing::{debug_span, Instrument}; @@ -30,6 +30,7 @@ mod keys; mod linking; mod profile; mod registration; +mod response; mod stickers; pub use account::*; @@ -39,6 +40,7 @@ pub use keys::*; pub use linking::*; pub use profile::*; pub use registration::*; +pub(crate) use response::{ReqwestExt, SignalServiceResponse}; #[derive(Debug, Serialize, Deserialize)] pub struct ProofRequired { @@ -204,147 +206,7 @@ impl PushService { Ok(builder) } -} - -#[async_trait::async_trait] -pub(crate) trait ReqwestExt -where - Self: Sized, -{ - async fn send_to_signal(self) -> Result; -} - -#[async_trait::async_trait] -impl ReqwestExt for RequestBuilder { - async fn send_to_signal(self) -> Result { - let response = self.send().await?; - match response.status() { - StatusCode::OK => Ok(response), - StatusCode::NO_CONTENT => Ok(response), - StatusCode::UNAUTHORIZED | StatusCode::FORBIDDEN => { - Err(ServiceError::Unauthorized) - }, - StatusCode::NOT_FOUND => { - // This is 404 and means that e.g. recipient is not registered - Err(ServiceError::NotFoundError) - }, - StatusCode::PAYLOAD_TOO_LARGE => { - // This is 413 and means rate limit exceeded for Signal. - Err(ServiceError::RateLimitExceeded) - }, - StatusCode::CONFLICT => { - let mismatched_devices = - response.json().await.map_err(|error| { - tracing::error!( - %error, - "failed to decode HTTP 409 status" - ); - ServiceError::UnhandledResponseCode { - http_code: StatusCode::CONFLICT.as_u16(), - } - })?; - Err(ServiceError::MismatchedDevicesException( - mismatched_devices, - )) - }, - StatusCode::GONE => { - let stale_devices = response.json().await.map_err(|error| { - tracing::error!(%error, "failed to decode HTTP 410 status"); - ServiceError::UnhandledResponseCode { - http_code: StatusCode::GONE.as_u16(), - } - })?; - Err(ServiceError::StaleDevices(stale_devices)) - }, - StatusCode::LOCKED => { - let locked = response.json().await.map_err(|error| { - tracing::error!(%error, "failed to decode HTTP 423 status"); - ServiceError::UnhandledResponseCode { - http_code: StatusCode::LOCKED.as_u16(), - } - })?; - Err(ServiceError::Locked(locked)) - }, - StatusCode::PRECONDITION_REQUIRED => { - let proof_required = - response.json().await.map_err(|error| { - tracing::error!( - %error, - "failed to decode HTTP 428 status" - ); - ServiceError::UnhandledResponseCode { - http_code: StatusCode::PRECONDITION_REQUIRED - .as_u16(), - } - })?; - Err(ServiceError::ProofRequiredError(proof_required)) - }, - // XXX: fill in rest from PushServiceSocket - code => { - let response_text = response.text().await?; - tracing::trace!(status_code =% code, body = response_text, "unhandled HTTP response"); - Err(ServiceError::UnhandledResponseCode { - http_code: code.as_u16(), - }) - }, - } - } -} - -pub(crate) mod protobuf { - use async_trait::async_trait; - use prost::{EncodeError, Message}; - use reqwest::{header, RequestBuilder, Response}; - - use super::ServiceError; - - pub(crate) trait ProtobufRequestBuilderExt - where - Self: Sized, - { - /// Set the request payload encoded as protobuf. - /// Sets the `Content-Type` header to `application/protobuf` - #[allow(dead_code)] - fn protobuf( - self, - value: T, - ) -> Result; - } - - #[async_trait::async_trait] - pub(crate) trait ProtobufResponseExt { - /// Get the response body decoded from Protobuf - async fn protobuf( - self, - ) -> Result; - } - - impl ProtobufRequestBuilderExt for RequestBuilder { - fn protobuf( - self, - value: T, - ) -> Result { - let mut buf = Vec::new(); - value.encode(&mut buf)?; - let this = - self.header(header::CONTENT_TYPE, "application/protobuf"); - Ok(this.body(buf)) - } - } - - #[async_trait] - impl ProtobufResponseExt for Response { - async fn protobuf( - self, - ) -> Result { - let body = self.bytes().await?; - let decoded = T::decode(body)?; - Ok(decoded) - } - } -} -impl PushService { pub async fn ws( &mut self, path: &str, @@ -399,12 +261,67 @@ impl PushService { )? .send() .await? + .service_error_for_status() + .await? .protobuf() .await .map_err(Into::into) } } +pub(crate) mod protobuf { + use async_trait::async_trait; + use prost::{EncodeError, Message}; + use reqwest::{header, RequestBuilder, Response}; + + use super::ServiceError; + + pub(crate) trait ProtobufRequestBuilderExt + where + Self: Sized, + { + /// Set the request payload encoded as protobuf. + /// Sets the `Content-Type` header to `application/protobuf` + #[allow(dead_code)] + fn protobuf( + self, + value: T, + ) -> Result; + } + + #[async_trait::async_trait] + pub(crate) trait ProtobufResponseExt { + /// Get the response body decoded from Protobuf + async fn protobuf( + self, + ) -> Result; + } + + impl ProtobufRequestBuilderExt for RequestBuilder { + fn protobuf( + self, + value: T, + ) -> Result { + let mut buf = Vec::new(); + value.encode(&mut buf)?; + let this = + self.header(header::CONTENT_TYPE, "application/protobuf"); + Ok(this.body(buf)) + } + } + + #[async_trait] + impl ProtobufResponseExt for Response { + async fn protobuf( + self, + ) -> Result { + let body = self.bytes().await?; + let decoded = T::decode(body)?; + Ok(decoded) + } + } +} + #[cfg(test)] mod tests { use crate::configuration::SignalServers; diff --git a/src/push_service/profile.rs b/src/push_service/profile.rs index b05aef56c..c48c67679 100644 --- a/src/push_service/profile.rs +++ b/src/push_service/profile.rs @@ -109,7 +109,7 @@ impl PushService { &endpoint, HttpAuthOverride::NoOverride, )? - .send_to_signal() + .send().await?.service_error_for_status() .await? .json() .await @@ -174,7 +174,7 @@ impl PushService { HttpAuthOverride::NoOverride, )? .json(&command) - .send_to_signal() + .send().await?.service_error_for_status() .await? .json() .await; diff --git a/src/push_service/registration.rs b/src/push_service/registration.rs index f968b6add..3e56f1da9 100644 --- a/src/push_service/registration.rs +++ b/src/push_service/registration.rs @@ -8,7 +8,7 @@ use super::{AccountAttributes, PushService, ServiceError}; use crate::{ configuration::Endpoint, pre_keys::{KyberPreKeyEntity, SignedPreKeyEntity}, - push_service::{HttpAuthOverride, ReqwestExt}, + push_service::{response::ReqwestExt, HttpAuthOverride}, utils::serde_base64, }; @@ -168,7 +168,9 @@ impl PushService { device_activation_request, every_signed_key_valid: true, }) - .send_to_signal() + .send() + .await? + .service_error_for_status() .await? .json() .await @@ -207,7 +209,9 @@ impl PushService { mcc, mnc, }) - .send_to_signal() + .send() + .await? + .service_error_for_status() .await? .json() .await @@ -248,7 +252,9 @@ impl PushService { mnc, push_challenge, }) - .send_to_signal() + .send() + .await? + .service_error_for_status() .await? .json() .await @@ -288,7 +294,9 @@ impl PushService { HttpAuthOverride::Unidentified, )? .json(&VerificationCodeRequest { transport, client }) - .send_to_signal() + .send() + .await? + .service_error_for_status() .await? .json() .await @@ -314,7 +322,9 @@ impl PushService { .json(&VerificationCode { code: verification_code, }) - .send_to_signal() + .send() + .await? + .service_error_for_status() .await? .json() .await diff --git a/src/push_service/response.rs b/src/push_service/response.rs new file mode 100644 index 000000000..9fc02c6e9 --- /dev/null +++ b/src/push_service/response.rs @@ -0,0 +1,160 @@ +use reqwest::StatusCode; + +use crate::proto::WebSocketResponseMessage; + +use super::ServiceError; + +async fn service_error_for_status(response: R) -> Result +where + R: SignalServiceResponse, + ServiceError: From<::Error>, +{ + match response.status_code() { + StatusCode::OK => Ok(response), + StatusCode::NO_CONTENT => Ok(response), + StatusCode::UNAUTHORIZED | StatusCode::FORBIDDEN => { + Err(ServiceError::Unauthorized) + }, + StatusCode::NOT_FOUND => { + // This is 404 and means that e.g. recipient is not registered + Err(ServiceError::NotFoundError) + }, + StatusCode::PAYLOAD_TOO_LARGE => { + // This is 413 and means rate limit exceeded for Signal. + Err(ServiceError::RateLimitExceeded) + }, + StatusCode::CONFLICT => { + let mismatched_devices = + response.json().await.map_err(|error| { + tracing::error!( + %error, + "failed to decode HTTP 409 status" + ); + ServiceError::UnhandledResponseCode { + http_code: StatusCode::CONFLICT.as_u16(), + } + })?; + Err(ServiceError::MismatchedDevicesException(mismatched_devices)) + }, + StatusCode::GONE => { + let stale_devices = response.json().await.map_err(|error| { + tracing::error!(%error, "failed to decode HTTP 410 status"); + ServiceError::UnhandledResponseCode { + http_code: StatusCode::GONE.as_u16(), + } + })?; + Err(ServiceError::StaleDevices(stale_devices)) + }, + StatusCode::LOCKED => { + let locked = response.json().await.map_err(|error| { + tracing::error!(%error, "failed to decode HTTP 423 status"); + ServiceError::UnhandledResponseCode { + http_code: StatusCode::LOCKED.as_u16(), + } + })?; + Err(ServiceError::Locked(locked)) + }, + StatusCode::PRECONDITION_REQUIRED => { + let proof_required = response.json().await.map_err(|error| { + tracing::error!( + %error, + "failed to decode HTTP 428 status" + ); + ServiceError::UnhandledResponseCode { + http_code: StatusCode::PRECONDITION_REQUIRED.as_u16(), + } + })?; + Err(ServiceError::ProofRequiredError(proof_required)) + }, + // XXX: fill in rest from PushServiceSocket + code => { + let response_text = response.text().await?; + tracing::trace!(status_code =% code, body = response_text, "unhandled HTTP response"); + Err(ServiceError::UnhandledResponseCode { + http_code: code.as_u16(), + }) + }, + } +} + +#[async_trait::async_trait] +pub(crate) trait SignalServiceResponse { + type Error: std::error::Error; + + fn status_code(&self) -> StatusCode; + + async fn json(self) -> Result + where + for<'de> U: serde::Deserialize<'de>; + + async fn text(self) -> Result; +} + +#[async_trait::async_trait] +impl SignalServiceResponse for reqwest::Response { + type Error = reqwest::Error; + + fn status_code(&self) -> StatusCode { + self.status() + } + + async fn json(self) -> Result + where + for<'de> U: serde::Deserialize<'de>, + { + reqwest::Response::json(self).await + } + + async fn text(self) -> Result { + reqwest::Response::text(self).await + } +} + +#[async_trait::async_trait] +impl SignalServiceResponse for WebSocketResponseMessage { + type Error = ServiceError; + + fn status_code(&self) -> StatusCode { + StatusCode::from_u16(self.status() as u16).unwrap_or_default() + } + + async fn json(self) -> Result + where + for<'de> U: serde::Deserialize<'de>, + { + serde_json::from_slice(self.body()).map_err(Into::into) + } + + async fn text(self) -> Result { + Ok(self + .body + .map(|body| String::from_utf8_lossy(&body).to_string()) + .unwrap_or_default()) + } +} + +#[async_trait::async_trait] +pub(crate) trait ReqwestExt +where + Self: Sized, +{ + /// convenience error handler to be used in the builder-style API of `reqwest::Response` + async fn service_error_for_status( + self, + ) -> Result; +} + +#[async_trait::async_trait] +impl ReqwestExt for reqwest::Response { + async fn service_error_for_status( + self, + ) -> Result { + service_error_for_status(self).await + } +} + +impl WebSocketResponseMessage { + pub async fn service_error_for_status(self) -> Result { + service_error_for_status(self).await + } +} diff --git a/src/websocket/mod.rs b/src/websocket/mod.rs index c423bf65a..1350bab7c 100644 --- a/src/websocket/mod.rs +++ b/src/websocket/mod.rs @@ -17,7 +17,7 @@ use crate::proto::{ web_socket_message, WebSocketMessage, WebSocketRequestMessage, WebSocketResponseMessage, }; -use crate::push_service::{self, MismatchedDevices, ServiceError}; +use crate::push_service::{self, ServiceError, SignalServiceResponse}; mod sender; // pub(crate) mod tungstenite; @@ -432,95 +432,16 @@ impl SignalWebSocket { where for<'de> T: serde::Deserialize<'de>, { - let response = self.request(r).await?; - if response.status() != 200 { - tracing::debug!( - "request_json with non-200 status code. message: {}", - response.message() - ); - } - - fn json(body: &[u8]) -> Result - where - for<'de> U: serde::Deserialize<'de>, - { - serde_json::from_slice(body).map_err(|e| { - ServiceError::JsonDecodeError { - reason: e.to_string(), - } - }) - } - - match response.status() { - 200 | 204 => json(response.body()), - 401 | 403 => Err(ServiceError::Unauthorized), - 404 => Err(ServiceError::NotFoundError), - 413 /* PAYLOAD_TOO_LARGE */ => Err(ServiceError::RateLimitExceeded) , - 409 /* CONFLICT */ => { - let mismatched_devices: MismatchedDevices = - json(response.body()).map_err(|e| { - tracing::error!( - "Failed to decode HTTP 409 response: {}", - e - ); - ServiceError::UnhandledResponseCode { - http_code: 409, - } - })?; - Err(ServiceError::MismatchedDevicesException( - mismatched_devices, - )) - }, - 410 /* GONE */ => { - let stale_devices = - json(response.body()).map_err(|e| { - tracing::error!( - "Failed to decode HTTP 410 response: {}", - e - ); - ServiceError::UnhandledResponseCode { - http_code: 410, - } - })?; - Err(ServiceError::StaleDevices(stale_devices)) - }, - 423 /* LOCKED */ => { - let locked = json(response.body()).map_err(|e| { - tracing::error!("Failed to decode HTTP 423 response: {}", e); - ServiceError::UnhandledResponseCode { - http_code: 423, - } - })?; - Err(ServiceError::Locked(locked)) - }, - 428 /* PRECONDITION_REQUIRED */ => { - let proof_required = json(response.body()).map_err(|e| { - tracing::error!("Failed to decode HTTP 428 response: {}", e); - ServiceError::UnhandledResponseCode { - http_code: 428, - } - })?; - Err(ServiceError::ProofRequiredError(proof_required)) - }, - _ => Err(ServiceError::UnhandledResponseCode { - http_code: response.status() as u16, - }), - } - } - - pub(crate) async fn put_json( - &mut self, - path: &str, - value: S, - ) -> Result - where - for<'de> D: Deserialize<'de>, - S: Serialize, - { - self.put_json_with_headers(path, value, vec![]).await + self.request(r) + .await? + .service_error_for_status() + .await? + .json() + .await + .map_err(Into::into) } - pub(crate) async fn put_json_with_headers<'h, D, S>( + pub(crate) async fn put_json<'h, D, S>( &mut self, path: &str, value: S, diff --git a/src/websocket/sender.rs b/src/websocket/sender.rs index e9ea90ef6..341430b38 100644 --- a/src/websocket/sender.rs +++ b/src/websocket/sender.rs @@ -13,7 +13,7 @@ impl SignalWebSocket { messages: OutgoingPushMessages, ) -> Result { let path = format!("/v1/messages/{}", messages.destination); - self.put_json(&path, messages).await + self.put_json(&path, messages, vec![]).await } pub async fn send_messages_unidentified( @@ -26,7 +26,6 @@ impl SignalWebSocket { "Unidentified-Access-Key:{}", BASE64_RELAXED.encode(&access.key) ); - self.put_json_with_headers(&path, messages, vec![header]) - .await + self.put_json(&path, messages, vec![header]).await } }