Skip to content

Commit

Permalink
feat: Provide support for upgrading HTTP requests (#291)
Browse files Browse the repository at this point in the history
This lays the groundwork for upgrading HTTP requests from query calls to update
calls.

It applies the changes from #195 that
are specific to ic-utils so that they can be used downstream in icx-proxy.
  • Loading branch information
paulyoung authored Dec 22, 2021
1 parent 0fb0ae3 commit 8872586
Showing 1 changed file with 24 additions and 1 deletion.
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

0 comments on commit 8872586

Please sign in to comment.