diff --git a/ic-utils/src/interfaces/http_request.rs b/ic-utils/src/interfaces/http_request.rs index 95f7fb41..a940fa2c 100644 --- a/ic-utils/src/interfaces/http_request.rs +++ b/ic-utils/src/interfaces/http_request.rs @@ -126,3 +126,58 @@ impl<'agent> Canister<'agent, HttpRequestCanister> { self.query_(&method.into()).with_arg(token).build() } } + +#[cfg(test)] +mod test { + use super::HttpResponse; + use candid::{Decode, Encode}; + + mod pre_update_legacy { + use candid::{CandidType, Deserialize, Func, Nat}; + use serde_bytes::ByteBuf; + + #[derive(CandidType, Deserialize)] + pub struct Token { + key: String, + content_encoding: String, + index: Nat, + sha256: Option, + } + + #[derive(CandidType, Deserialize)] + pub struct CallbackStrategy { + pub callback: Func, + pub token: Token, + } + + #[derive(CandidType, Clone, Deserialize)] + pub struct HeaderField(pub String, pub String); + + #[derive(CandidType, Deserialize)] + pub enum StreamingStrategy { + Callback(CallbackStrategy), + } + + #[derive(CandidType, Deserialize)] + pub struct HttpResponse { + pub status_code: u16, + pub headers: Vec, + #[serde(with = "serde_bytes")] + pub body: Vec, + pub streaming_strategy: Option, + } + } + + #[test] + fn deserialize_legacy_http_response() { + let bytes: Vec = Encode!(&pre_update_legacy::HttpResponse { + status_code: 100, + headers: Vec::new(), + body: Vec::new(), + streaming_strategy: None, + }) + .unwrap(); + + let _response = Decode!(&bytes, HttpResponse).unwrap(); + } +}