summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'runtime')
-rw-r--r--runtime/http_util.rs42
-rw-r--r--runtime/lib.rs1
-rw-r--r--runtime/ops/fetch.rs9
3 files changed, 7 insertions, 45 deletions
diff --git a/runtime/http_util.rs b/runtime/http_util.rs
deleted file mode 100644
index 72d41d6e3..000000000
--- a/runtime/http_util.rs
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
-
-use deno_core::error::generic_error;
-use deno_core::error::AnyError;
-use deno_fetch::reqwest;
-use deno_fetch::reqwest::header::HeaderMap;
-use deno_fetch::reqwest::header::USER_AGENT;
-use deno_fetch::reqwest::redirect::Policy;
-use deno_fetch::reqwest::Client;
-
-/// Create new instance of async reqwest::Client. This client supports
-/// proxies and doesn't follow redirects.
-pub fn create_http_client(
- user_agent: String,
- ca_data: Option<Vec<u8>>,
-) -> Result<Client, AnyError> {
- let mut headers = HeaderMap::new();
- headers.insert(USER_AGENT, user_agent.parse().unwrap());
- let mut builder = Client::builder()
- .redirect(Policy::none())
- .default_headers(headers)
- .use_rustls_tls();
-
- if let Some(ca_data) = ca_data {
- let cert = reqwest::Certificate::from_pem(&ca_data)?;
- builder = builder.add_root_certificate(cert);
- }
-
- builder
- .build()
- .map_err(|e| generic_error(format!("Unable to build http client: {}", e)))
-}
-
-#[cfg(test)]
-mod tests {
- use super::*;
-
- #[test]
- fn create_test_client() {
- create_http_client("test_client".to_string(), None).unwrap();
- }
-}
diff --git a/runtime/lib.rs b/runtime/lib.rs
index f4cf559d2..b30f10bd1 100644
--- a/runtime/lib.rs
+++ b/runtime/lib.rs
@@ -19,7 +19,6 @@ pub use deno_websocket;
pub mod colors;
pub mod errors;
pub mod fs_util;
-pub mod http_util;
pub mod inspector;
pub mod js;
pub mod metrics;
diff --git a/runtime/ops/fetch.rs b/runtime/ops/fetch.rs
index e1b43c910..9ab86858d 100644
--- a/runtime/ops/fetch.rs
+++ b/runtime/ops/fetch.rs
@@ -1,7 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
-use crate::http_util;
use crate::permissions::Permissions;
use deno_fetch::reqwest;
+use deno_fetch::HttpClientDefaults;
pub fn init(
rt: &mut deno_core::JsRuntime,
@@ -12,7 +12,12 @@ pub fn init(
let op_state = rt.op_state();
let mut state = op_state.borrow_mut();
state.put::<reqwest::Client>({
- http_util::create_http_client(user_agent, ca_data).unwrap()
+ deno_fetch::create_http_client(user_agent.clone(), ca_data.clone())
+ .unwrap()
+ });
+ state.put::<HttpClientDefaults>(HttpClientDefaults {
+ ca_data,
+ user_agent,
});
}
super::reg_json_sync(rt, "op_fetch", deno_fetch::op_fetch::<Permissions>);