Skip to content

Commit 3b90f7b

Browse files
authored
chore(PocketIC): include X_OC_JWT and X_OC_API_KEY cors headers in PocketIC HTTP gateway (#4154)
This PR reflects ic-gateway [PR](dfinity/ic-gateway#65) in the PocketIC HTTP gateway implementation.
1 parent a4de262 commit 3b90f7b

File tree

1 file changed

+35
-2
lines changed
  • rs/pocket_ic_server/src/state_api

1 file changed

+35
-2
lines changed

rs/pocket_ic_server/src/state_api/state.rs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use http::{
2727
HeaderName, Method, StatusCode,
2828
};
2929
use ic_bn_lib::http::body::buffer_body;
30+
use ic_bn_lib::http::headers::{X_IC_CANISTER_ID, X_REQUESTED_WITH, X_REQUEST_ID};
3031
use ic_bn_lib::http::proxy::proxy;
3132
use ic_bn_lib::http::{Client, Error as IcBnError};
3233
use ic_http_gateway::{CanisterRequest, HttpGatewayClient, HttpGatewayRequestArgs};
@@ -423,10 +424,12 @@ fn received_stop_signal(rx: &mut Receiver<()>) -> bool {
423424

424425
// ADAPTED from ic-gateway
425426

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

430+
const X_OC_JWT: HeaderName = HeaderName::from_static("x-oc-jwt");
431+
const X_OC_API_KEY: HeaderName = HeaderName::from_static("x-oc-api-key");
432+
430433
fn layer(methods: &[Method]) -> CorsLayer {
431434
CorsLayer::new()
432435
.allow_origin(Any)
@@ -435,6 +438,33 @@ fn layer(methods: &[Method]) -> CorsLayer {
435438
ACCEPT_RANGES,
436439
CONTENT_LENGTH,
437440
CONTENT_RANGE,
441+
X_REQUEST_ID,
442+
X_IC_CANISTER_ID,
443+
])
444+
.allow_headers([
445+
USER_AGENT,
446+
DNT,
447+
IF_NONE_MATCH,
448+
IF_MODIFIED_SINCE,
449+
CACHE_CONTROL,
450+
CONTENT_TYPE,
451+
RANGE,
452+
COOKIE,
453+
X_REQUESTED_WITH,
454+
X_IC_CANISTER_ID,
455+
])
456+
.max_age(10 * MINUTE)
457+
}
458+
459+
fn http_gw_layer(methods: &[Method]) -> CorsLayer {
460+
CorsLayer::new()
461+
.allow_origin(Any)
462+
.allow_methods(methods.to_vec())
463+
.expose_headers([
464+
ACCEPT_RANGES,
465+
CONTENT_LENGTH,
466+
CONTENT_RANGE,
467+
X_REQUEST_ID,
438468
X_IC_CANISTER_ID,
439469
])
440470
.allow_headers([
@@ -446,7 +476,10 @@ fn layer(methods: &[Method]) -> CorsLayer {
446476
CONTENT_TYPE,
447477
RANGE,
448478
COOKIE,
479+
X_REQUESTED_WITH,
449480
X_IC_CANISTER_ID,
481+
X_OC_JWT,
482+
X_OC_API_KEY,
450483
])
451484
.max_age(10 * MINUTE)
452485
}
@@ -890,7 +923,7 @@ impl ApiState {
890923
.put(handler)
891924
.delete(handler)
892925
.patch(handler)
893-
.layer(layer(&[
926+
.layer(http_gw_layer(&[
894927
Method::HEAD,
895928
Method::GET,
896929
Method::POST,

0 commit comments

Comments
 (0)