From 7f3a34eeb89e7c930b8189f95c5f8715185da587 Mon Sep 17 00:00:00 2001 From: Satya Rohith Date: Wed, 28 Jul 2021 04:34:08 +0530 Subject: [PATCH] feat(extensions/fetch): extend init options (#11528) --- extensions/fetch/lib.rs | 12 ++++++++++++ runtime/build.rs | 1 + runtime/web_worker.rs | 1 + runtime/worker.rs | 1 + 4 files changed, 15 insertions(+) diff --git a/extensions/fetch/lib.rs b/extensions/fetch/lib.rs index f870c58dc7..074e8827a6 100644 --- a/extensions/fetch/lib.rs +++ b/extensions/fetch/lib.rs @@ -60,6 +60,7 @@ pub fn init( user_agent: String, ca_data: Option>, proxy: Option, + frozen_headers: Option, ) -> Extension { Extension::builder() .js(include_js_files!( @@ -89,6 +90,7 @@ pub fn init( ca_data: ca_data.clone(), user_agent: user_agent.clone(), proxy: proxy.clone(), + frozen_headers: frozen_headers.clone(), }); Ok(()) }) @@ -99,6 +101,7 @@ pub struct HttpClientDefaults { pub user_agent: String, pub ca_data: Option>, pub proxy: Option, + pub frozen_headers: Option, } pub trait FetchPermissions { @@ -214,6 +217,15 @@ where } } + // Set frozen_headers after the user provided headers, so the + // end user can't override them. + let defaults = state.borrow::(); + if let Some(frozen_headers) = &defaults.frozen_headers { + for (key, value) in frozen_headers { + request = request.header(key, value) + } + } + let cancel_handle = CancelHandle::new_rc(); let cancel_handle_ = cancel_handle.clone(); diff --git a/runtime/build.rs b/runtime/build.rs index 0d1cf3bce6..4e061c4386 100644 --- a/runtime/build.rs +++ b/runtime/build.rs @@ -46,6 +46,7 @@ fn create_runtime_snapshot(snapshot_path: &Path, files: Vec) { "".to_owned(), None, None, + None, ), deno_websocket::init::( "".to_owned(), diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs index bcbf716929..5724517a00 100644 --- a/runtime/web_worker.rs +++ b/runtime/web_worker.rs @@ -301,6 +301,7 @@ impl WebWorker { options.user_agent.clone(), options.ca_data.clone(), None, + None, ), deno_websocket::init::( options.user_agent.clone(), diff --git a/runtime/worker.rs b/runtime/worker.rs index 18ba348ff5..c8c93d2f01 100644 --- a/runtime/worker.rs +++ b/runtime/worker.rs @@ -101,6 +101,7 @@ impl MainWorker { options.user_agent.clone(), options.ca_data.clone(), None, + None, ), deno_websocket::init::( options.user_agent.clone(),