From 235fe1669f9f658261c895a08d12124368ee5bb2 Mon Sep 17 00:00:00 2001 From: Ruben De Smet Date: Sat, 20 Jun 2020 20:15:41 +0200 Subject: [PATCH] Allow debugging the passing through JSON data. --- libsignal-service-actix/Cargo.toml | 1 + libsignal-service-actix/src/push_service.rs | 30 +++++++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/libsignal-service-actix/Cargo.toml b/libsignal-service-actix/Cargo.toml index ca751cedb..32ddfa56a 100644 --- a/libsignal-service-actix/Cargo.toml +++ b/libsignal-service-actix/Cargo.toml @@ -12,6 +12,7 @@ libsignal-protocol = { git = "https://github.com/Michael-F-Bryan/libsignal-proto awc = { version = "2.0.0-alpha.2", features=["rustls"] } actix-rt = "1.1" +serde_json = "1.0" rustls = "0.17" url = "2.1" serde = "1.0" diff --git a/libsignal-service-actix/src/push_service.rs b/libsignal-service-actix/src/push_service.rs index 899bb6cee..43bb3043c 100644 --- a/libsignal-service-actix/src/push_service.rs +++ b/libsignal-service-actix/src/push_service.rs @@ -35,12 +35,32 @@ impl PushService for AwcPushService { ServiceError::from_status(response.status())?; - response - .json() - .await - .map_err(|e| ServiceError::JsonDecodeError { - reason: e.to_string(), + // In order to debug the output, we collect the whole response. + // The actix-web api is meant to used as a streaming deserializer, + // so we have this little awkward switch. + // + // This is also the reason we depend directly on serde_json, however + // actix already imports that anyway. + if log::log_enabled!(log::Level::Debug) { + let text = response.body().await.map_err(|e| { + ServiceError::JsonDecodeError { + reason: e.to_string(), + } + })?; + log::debug!("GET response: {:?}", String::from_utf8_lossy(&text)); + serde_json::from_slice(&text).map_err(|e| { + ServiceError::JsonDecodeError { + reason: e.to_string(), + } }) + } else { + response + .json() + .await + .map_err(|e| ServiceError::JsonDecodeError { + reason: e.to_string(), + }) + } } }