mirror of
https://github.com/denoland/deno.git
synced 2024-11-22 04:51:22 +00:00
feat(extensions/fetch): extend init options (#11528)
This commit is contained in:
parent
667b026798
commit
7f3a34eeb8
@ -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();
|
||||
|
||||
|
@ -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(),
|
||||
|
@ -301,6 +301,7 @@ impl WebWorker {
|
||||
options.user_agent.clone(),
|
||||
options.ca_data.clone(),
|
||||
None,
|
||||
None,
|
||||
),
|
||||
deno_websocket::init::<Permissions>(
|
||||
options.user_agent.clone(),
|
||||
|
@ -101,6 +101,7 @@ impl MainWorker {
|
||||
options.user_agent.clone(),
|
||||
options.ca_data.clone(),
|
||||
None,
|
||||
None,
|
||||
),
|
||||
deno_websocket::init::<Permissions>(
|
||||
options.user_agent.clone(),
|
||||
|
Loading…
Reference in New Issue
Block a user