diff options
author | Satya Rohith <me@satyarohith.com> | 2021-07-28 04:34:08 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-28 04:34:08 +0530 |
commit | 7f3a34eeb89e7c930b8189f95c5f8715185da587 (patch) | |
tree | 6a536ed20b91a3836b589600a37c9a4684e1aec3 | |
parent | 667b026798b5284e9ec8bf47baba80f343975d2e (diff) |
feat(extensions/fetch): extend init options (#11528)
-rw-r--r-- | extensions/fetch/lib.rs | 12 | ||||
-rw-r--r-- | runtime/build.rs | 1 | ||||
-rw-r--r-- | runtime/web_worker.rs | 1 | ||||
-rw-r--r-- | runtime/worker.rs | 1 |
4 files changed, 15 insertions, 0 deletions
diff --git a/extensions/fetch/lib.rs b/extensions/fetch/lib.rs index f870c58dc..074e8827a 100644 --- a/extensions/fetch/lib.rs +++ b/extensions/fetch/lib.rs @@ -60,6 +60,7 @@ pub fn init<P: FetchPermissions + 'static>( user_agent: String, ca_data: Option<Vec<u8>>, proxy: Option<Proxy>, + frozen_headers: Option<HeaderMap>, ) -> Extension { Extension::builder() .js(include_js_files!( @@ -89,6 +90,7 @@ pub fn init<P: FetchPermissions + 'static>( 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<Vec<u8>>, pub proxy: Option<Proxy>, + pub frozen_headers: Option<HeaderMap>, } 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::<HttpClientDefaults>(); + 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 0d1cf3bce..4e061c438 100644 --- a/runtime/build.rs +++ b/runtime/build.rs @@ -46,6 +46,7 @@ fn create_runtime_snapshot(snapshot_path: &Path, files: Vec<PathBuf>) { "".to_owned(), None, None, + None, ), deno_websocket::init::<deno_websocket::NoWebSocketPermissions>( "".to_owned(), diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs index bcbf71692..5724517a0 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::<Permissions>( options.user_agent.clone(), diff --git a/runtime/worker.rs b/runtime/worker.rs index 18ba348ff..c8c93d2f0 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::<Permissions>( options.user_agent.clone(), |