Skip to content

Commit

Permalink
feat(extensions/fetch): extend init options (denoland#11528)
Browse files Browse the repository at this point in the history
  • Loading branch information
satyarohith committed Jul 27, 2021
1 parent 667b026 commit 7f3a34e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions extensions/fetch/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down Expand Up @@ -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(())
})
Expand All @@ -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 {
Expand Down Expand Up @@ -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();

Expand Down
1 change: 1 addition & 0 deletions runtime/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions runtime/web_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ impl WebWorker {
options.user_agent.clone(),
options.ca_data.clone(),
None,
None,
),
deno_websocket::init::<Permissions>(
options.user_agent.clone(),
Expand Down
1 change: 1 addition & 0 deletions runtime/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ impl MainWorker {
options.user_agent.clone(),
options.ca_data.clone(),
None,
None,
),
deno_websocket::init::<Permissions>(
options.user_agent.clone(),
Expand Down

0 comments on commit 7f3a34e

Please sign in to comment.