diff options
Diffstat (limited to 'extensions/fetch/lib.rs')
-rw-r--r-- | extensions/fetch/lib.rs | 12 |
1 files changed, 12 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(); |