Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions ic-utils/src/interfaces/http_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ByteBuf>,
}

#[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<HeaderField>,
#[serde(with = "serde_bytes")]
pub body: Vec<u8>,
pub streaming_strategy: Option<StreamingStrategy>,
}
}

#[test]
fn deserialize_legacy_http_response() {
let bytes: Vec<u8> = Encode!(&pre_update_legacy::HttpResponse {
status_code: 100,
headers: Vec::new(),
body: Vec::new(),
streaming_strategy: None,
})
.unwrap();

let _response = Decode!(&bytes, HttpResponse).unwrap();
}
}