1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-29 16:30:56 -05:00

feat(extensions/fetch): extend init options (#11528)

This commit is contained in:
Satya Rohith 2021-07-28 04:34:08 +05:30 committed by GitHub
parent 667b026798
commit 7f3a34eeb8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 0 deletions

View file

@ -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();

View file

@ -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(),

View file

@ -301,6 +301,7 @@ impl WebWorker {
options.user_agent.clone(),
options.ca_data.clone(),
None,
None,
),
deno_websocket::init::<Permissions>(
options.user_agent.clone(),

View file

@ -101,6 +101,7 @@ impl MainWorker {
options.user_agent.clone(),
options.ca_data.clone(),
None,
None,
),
deno_websocket::init::<Permissions>(
options.user_agent.clone(),