ic_http_gateway/request/
http_gateway_request_builder.rs

1use crate::{protocol::process_request, HttpGatewayResponse};
2use bytes::Bytes;
3use candid::Principal;
4use http::Request;
5use ic_agent::Agent;
6
7pub struct HttpGatewayRequestArgs {
8    /// The request to make to the canister.
9    pub canister_request: CanisterRequest,
10
11    /// The id of the canister to make a request to.
12    pub canister_id: Principal,
13}
14
15pub type CanisterRequest = Request<Bytes>;
16
17pub struct HttpGatewayRequestBuilderArgs<'a> {
18    pub request_args: HttpGatewayRequestArgs,
19    pub agent: &'a Agent,
20}
21
22pub struct HttpGatewayRequestBuilder<'a> {
23    args: HttpGatewayRequestBuilderArgs<'a>,
24    skip_verification: bool,
25}
26
27impl<'a> HttpGatewayRequestBuilder<'a> {
28    pub fn new(args: HttpGatewayRequestBuilderArgs<'a>) -> Self {
29        Self {
30            args,
31            skip_verification: false,
32        }
33    }
34
35    pub fn unsafe_set_skip_verification(&mut self, skip_verification: bool) -> &mut Self {
36        self.skip_verification = skip_verification;
37
38        self
39    }
40
41    pub async fn send(self) -> HttpGatewayResponse {
42        process_request(
43            self.args.agent,
44            self.args.request_args.canister_request,
45            self.args.request_args.canister_id,
46            self.skip_verification,
47        )
48        .await
49    }
50}