From 3d2ebe3f02dfe1324ff791c0aa3a5d2cacbff3a3 Mon Sep 17 00:00:00 2001 From: Paul Young <84700+paulyoung@users.noreply.github.com> Date: Wed, 22 Dec 2021 14:30:16 -0800 Subject: [PATCH] feat: Provide support for upgrading HTTP requests This lays the groundwork for upgrading HTTP requests from query calls to update calls. It applies the changes from https://github.com/dfinity/agent-rs/pull/195 that are specific to ic-utils so that they can be used downstream in icx-proxy. --- ic-utils/src/interfaces/http_request.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/ic-utils/src/interfaces/http_request.rs b/ic-utils/src/interfaces/http_request.rs index 4ebb2057..72ca99cd 100644 --- a/ic-utils/src/interfaces/http_request.rs +++ b/ic-utils/src/interfaces/http_request.rs @@ -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; @@ -47,6 +47,7 @@ pub struct HttpResponse { #[serde(with = "serde_bytes")] pub body: Vec, pub streaming_strategy: Option, + pub upgrade: bool, } #[derive(CandidType, Deserialize)] @@ -95,6 +96,28 @@ impl<'agent> Canister<'agent, HttpRequestCanister> { .build() } + pub fn http_request_update< + 'canister: 'agent, + M: Into, + U: Into, + B: AsRef<[u8]>, + >( + &'canister self, + method: M, + url: U, + headers: Vec, + 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>( &'canister self, method: M,