Skip to content
Merged
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
37 changes: 35 additions & 2 deletions rs/pocket_ic_server/src/state_api/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use http::{
HeaderName, Method, StatusCode,
};
use ic_bn_lib::http::body::buffer_body;
use ic_bn_lib::http::headers::{X_IC_CANISTER_ID, X_REQUESTED_WITH, X_REQUEST_ID};
use ic_bn_lib::http::proxy::proxy;
use ic_bn_lib::http::{Client, Error as IcBnError};
use ic_http_gateway::{CanisterRequest, HttpGatewayClient, HttpGatewayRequestArgs};
Expand Down Expand Up @@ -423,10 +424,12 @@ fn received_stop_signal(rx: &mut Receiver<()>) -> bool {

// ADAPTED from ic-gateway

const X_IC_CANISTER_ID: HeaderName = HeaderName::from_static("x-ic-canister-id");
const MAX_REQUEST_BODY_SIZE: usize = 10 * 1_048_576;
const MINUTE: Duration = Duration::from_secs(60);

const X_OC_JWT: HeaderName = HeaderName::from_static("x-oc-jwt");
const X_OC_API_KEY: HeaderName = HeaderName::from_static("x-oc-api-key");

fn layer(methods: &[Method]) -> CorsLayer {
CorsLayer::new()
.allow_origin(Any)
Expand All @@ -435,6 +438,33 @@ fn layer(methods: &[Method]) -> CorsLayer {
ACCEPT_RANGES,
CONTENT_LENGTH,
CONTENT_RANGE,
X_REQUEST_ID,
X_IC_CANISTER_ID,
])
.allow_headers([
USER_AGENT,
DNT,
IF_NONE_MATCH,
IF_MODIFIED_SINCE,
CACHE_CONTROL,
CONTENT_TYPE,
RANGE,
COOKIE,
X_REQUESTED_WITH,
X_IC_CANISTER_ID,
])
.max_age(10 * MINUTE)
}

fn http_gw_layer(methods: &[Method]) -> CorsLayer {
CorsLayer::new()
.allow_origin(Any)
.allow_methods(methods.to_vec())
.expose_headers([
ACCEPT_RANGES,
CONTENT_LENGTH,
CONTENT_RANGE,
X_REQUEST_ID,
X_IC_CANISTER_ID,
])
.allow_headers([
Expand All @@ -446,7 +476,10 @@ fn layer(methods: &[Method]) -> CorsLayer {
CONTENT_TYPE,
RANGE,
COOKIE,
X_REQUESTED_WITH,
X_IC_CANISTER_ID,
X_OC_JWT,
X_OC_API_KEY,
])
.max_age(10 * MINUTE)
}
Expand Down Expand Up @@ -890,7 +923,7 @@ impl ApiState {
.put(handler)
.delete(handler)
.patch(handler)
.layer(layer(&[
.layer(http_gw_layer(&[
Method::HEAD,
Method::GET,
Method::POST,
Expand Down