Skip to content
Merged
Show file tree
Hide file tree
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
97 changes: 97 additions & 0 deletions rs/types/management_canister_types/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,3 +391,100 @@ pub struct CanisterHttpResponsePayload {
}

impl Payload<'_> for CanisterHttpResponsePayload {}

/// The result type for the `flexible_http_request` management canister endpoint.
///
/// ```text
/// type flexible_http_request_result = variant {
/// ok: vec http_request_result;
/// err: flexible_http_request_err;
/// };
/// ```
#[derive(Clone, Eq, PartialEq, Hash, Debug, CandidType, Deserialize, Serialize)]
pub enum FlexibleHttpRequestResult {
#[serde(rename = "ok")]
Ok(Vec<CanisterHttpResponsePayload>),
#[serde(rename = "err")]
Err(FlexibleHttpRequestErr),
}
Comment thread
michael-weigelt marked this conversation as resolved.

/// The error type returned by `flexible_http_request`.
///
/// ```text
/// type flexible_http_request_err = record {
/// global_error: opt variant { ... };
/// node_details : vec record { ... };
/// message: text;
/// };
/// ```
#[derive(Clone, Eq, PartialEq, Hash, Debug, CandidType, Deserialize, Serialize)]
pub struct FlexibleHttpRequestErr {
pub global_error: Option<FlexibleHttpGlobalError>,
pub node_details: Vec<FlexibleHttpNodeDetail>,
pub message: String,
}

/// Why the flexible HTTP outcall failed globally.
#[derive(Clone, Eq, PartialEq, Hash, Debug, CandidType, Deserialize, Serialize)]
pub enum FlexibleHttpGlobalError {
#[serde(rename = "invalid_parameters")]
InvalidParameters(candid::Reserved),
#[serde(rename = "timeout")]
Timeout(candid::Reserved),
#[serde(rename = "out_of_cycles")]
OutOfCycles(candid::Reserved),
#[serde(rename = "responses_too_large")]
ResponsesTooLarge(candid::Reserved),
}

/// Per-node detail in a flexible HTTP outcall error.
///
/// ```text
/// record {
/// node_id: principal;
/// report: http_request_resource_report;
/// error: opt record { code: text; message: text };
/// }
/// ```
#[derive(Clone, Eq, PartialEq, Hash, Debug, CandidType, Deserialize, Serialize)]
pub struct FlexibleHttpNodeDetail {
pub node_id: candid::Principal,
pub report: HttpRequestResourceReport,
pub error: Option<FlexibleHttpNodeError>,
}

/// Per-node resource usage accounting for an HTTP outcall.
///
/// ```text
/// type http_request_resource_report = record {
/// raw_response_bytes: opt variant { used: nat64; exceeded: reserved };
/// http_roundtrip_time_ms: opt variant { used: nat64; exceeded: reserved };
/// transform_instructions: opt variant { used: nat64; exceeded: reserved };
/// transformed_response_bytes: opt variant { used: nat64; exceeded: reserved };
/// cycles: opt variant { used: nat; exceeded: reserved };
/// };
/// ```
#[derive(Clone, Eq, PartialEq, Hash, Debug, CandidType, Deserialize, Serialize)]
pub struct HttpRequestResourceReport {
pub raw_response_bytes: Option<ResourceUsage<u64>>,
pub http_roundtrip_time_ms: Option<ResourceUsage<u64>>,
pub transform_instructions: Option<ResourceUsage<u64>>,
pub transformed_response_bytes: Option<ResourceUsage<u64>>,
pub cycles: Option<ResourceUsage<candid::Nat>>,
}

/// Tracks whether a resource was used or exceeded its budget.
#[derive(Clone, Eq, PartialEq, Hash, Debug, CandidType, Deserialize, Serialize)]
pub enum ResourceUsage<T> {
#[serde(rename = "used")]
Used(T),
#[serde(rename = "exceeded")]
Exceeded(candid::Reserved),
}

/// Error details from a specific node during a flexible HTTP outcall.
#[derive(Clone, Eq, PartialEq, Hash, Debug, CandidType, Deserialize, Serialize)]
pub struct FlexibleHttpNodeError {
pub code: String,
pub message: String,
}
7 changes: 4 additions & 3 deletions rs/types/management_canister_types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ pub use data_size::*;
pub use http::{
ALLOWED_HTTP_OUTCALLS_PRICING_VERSIONS, BoundedHttpHeaders, CanisterHttpRequestArgs,
CanisterHttpResponsePayload, DEFAULT_HTTP_OUTCALLS_PRICING_VERSION,
FlexibleCanisterHttpRequestArgs, HttpHeader, HttpMethod, PRICING_VERSION_LEGACY,
PRICING_VERSION_PAY_AS_YOU_GO, ReplicationCounts, TransformArgs, TransformContext,
TransformFunc,
FlexibleCanisterHttpRequestArgs, FlexibleHttpGlobalError, FlexibleHttpNodeDetail,
FlexibleHttpNodeError, FlexibleHttpRequestErr, FlexibleHttpRequestResult, HttpHeader,
HttpMethod, HttpRequestResourceReport, PRICING_VERSION_LEGACY, PRICING_VERSION_PAY_AS_YOU_GO,
ReplicationCounts, ResourceUsage, TransformArgs, TransformContext, TransformFunc,
};
use ic_base_types::{
CanisterId, EnvironmentVariables, NodeId, NumBytes, PrincipalId, RegistryVersion, SnapshotId,
Expand Down
Loading