ic_http_gateway/response/
http_gateway_response.rs

1use bytes::Bytes;
2use futures::stream::BoxStream;
3use http::Response;
4use http_body::Frame;
5use http_body_util::{Either, Full, StreamBody};
6use ic_agent::AgentError;
7use std::fmt::Debug;
8
9use crate::HttpGatewayError;
10
11pub type CanisterResponse = Response<HttpGatewayResponseBody>;
12
13/// A response from the HTTP gateway.
14pub struct HttpGatewayResponse {
15    /// The certified response, excluding uncertified headers.
16    /// If response verification v1 is used, the original, uncertified headers are returned.
17    pub canister_response: CanisterResponse,
18
19    /// Additional metadata regarding the response.
20    pub metadata: HttpGatewayResponseMetadata,
21}
22
23/// Additional metadata regarding the response.
24#[derive(Debug, Clone)]
25pub struct HttpGatewayResponseMetadata {
26    /// Whether the original query call was upgraded to an update call.
27    pub upgraded_to_update_call: bool,
28
29    /// The version of response verification that was used to verify the response.
30    /// If the protocol fails before getting to the verification step, or the
31    /// original query call is upgraded to an update call, this field will be `None`.
32    pub response_verification_version: Option<u16>,
33
34    /// The internal error that resulted in the HTTP response being an error response.
35    pub internal_error: Option<HttpGatewayError>,
36}
37
38pub type HttpGatewayResponseBody = Either<ResponseBodyStream, Full<Bytes>>;
39
40pub type ResponseBodyStream = StreamBody<BoxStream<'static, ResponseBodyStreamItem>>;
41
42/// An item in a response body stream.
43pub type ResponseBodyStreamItem = Result<Frame<Bytes>, AgentError>;