Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Provide support for upgrading HTTP requests #291

Merged
merged 1 commit into from
Dec 22, 2021
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
25 changes: 24 additions & 1 deletion ic-utils/src/interfaces/http_request.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{call::SyncCall, canister::CanisterBuilder, Canister};
use crate::{call::AsyncCall, call::SyncCall, canister::CanisterBuilder, Canister};
use candid::{CandidType, Deserialize, Func, Nat};
use ic_agent::{export::Principal, Agent};
use serde_bytes::ByteBuf;
Expand Down Expand Up @@ -47,6 +47,7 @@ pub struct HttpResponse {
#[serde(with = "serde_bytes")]
pub body: Vec<u8>,
pub streaming_strategy: Option<StreamingStrategy>,
pub upgrade: bool,
}

#[derive(CandidType, Deserialize)]
Expand Down Expand Up @@ -95,6 +96,28 @@ impl<'agent> Canister<'agent, HttpRequestCanister> {
.build()
}

pub fn http_request_update<
'canister: 'agent,
M: Into<String>,
U: Into<String>,
B: AsRef<[u8]>,
>(
&'canister self,
method: M,
url: U,
headers: Vec<HeaderField>,
body: B,
) -> impl 'agent + AsyncCall<(HttpResponse,)> {
self.update_("http_request_update")
.with_arg(HttpRequest {
method: method.into(),
url: url.into(),
headers,
body: body.as_ref(),
})
.build()
}

pub fn http_request_stream_callback<'canister: 'agent, M: Into<String>>(
&'canister self,
method: M,
Expand Down