diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/deno_dir.rs | 4 | ||||
-rw-r--r-- | src/handlers.rs | 2 | ||||
-rw-r--r-- | src/http.rs (renamed from src/net.rs) | 30 | ||||
-rw-r--r-- | src/main.rs | 4 |
4 files changed, 29 insertions, 11 deletions
diff --git a/src/deno_dir.rs b/src/deno_dir.rs index cdebf05c3..cb769fb86 100644 --- a/src/deno_dir.rs +++ b/src/deno_dir.rs @@ -4,7 +4,7 @@ use errors::DenoError; use errors::DenoResult; use errors::ErrorKind; use fs as deno_fs; -use net; +use http; use ring; use std; use std::fmt::Write; @@ -114,7 +114,7 @@ impl DenoDir { let src = if self.reload || !p.exists() { println!("Downloading {}", module_name); - let source = net::fetch_sync_string(module_name)?; + let source = http::fetch_sync_string(module_name)?; match p.parent() { Some(ref parent) => fs::create_dir_all(parent), None => Ok(()), diff --git a/src/handlers.rs b/src/handlers.rs index 964baabf8..623c64110 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -147,7 +147,7 @@ fn permission_denied() -> DenoError { fn not_implemented() -> DenoError { DenoError::from(std::io::Error::new( std::io::ErrorKind::Other, - "Not implemented" + "Not implemented", )) } diff --git a/src/net.rs b/src/http.rs index 7e0700bb6..5907b35ed 100644 --- a/src/net.rs +++ b/src/http.rs @@ -1,21 +1,37 @@ +// Copyright 2018 the Deno authors. All rights reserved. MIT license. + use errors::DenoResult; + +use futures::Future; +use futures::Stream; use hyper; -use hyper::rt::{Future, Stream}; -use hyper::{Client, Uri}; +use hyper::client::HttpConnector; +use hyper::Uri; use hyper_rustls; -use tokio::runtime::current_thread::Runtime; + +type Connector = hyper_rustls::HttpsConnector<HttpConnector>; + +lazy_static! { + static ref CONNECTOR: Connector = { + let num_dns_threads = 4; + Connector::new(num_dns_threads) + }; +} + +pub fn get_client() -> Client<Connector, hyper::Body> { + // TODO use Hyper's connection pool. + let c = CONNECTOR.clone(); + Client::builder().build(c) +} // The CodeFetch message is used to load HTTP javascript resources and expects a // synchronous response, this utility method supports that. pub fn fetch_sync_string(module_name: &str) -> DenoResult<String> { let url = module_name.parse::<Uri>().unwrap(); - - let https = hyper_rustls::HttpsConnector::new(4); - let client: Client<_, hyper::Body> = Client::builder().build(https); + let client = get_client(); // TODO Use Deno's RT let mut rt = Runtime::new().unwrap(); - let body = rt.block_on( client .get(url) diff --git a/src/main.rs b/src/main.rs index 8cf29dd37..1f9ead019 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,8 @@ extern crate tempfile; extern crate tokio; extern crate url; #[macro_use] +extern crate lazy_static; +#[macro_use] extern crate log; extern crate dirs; extern crate hyper_rustls; @@ -20,9 +22,9 @@ mod errors; mod flags; mod fs; pub mod handlers; +mod http; mod isolate; mod libdeno; -mod net; mod version; use isolate::Isolate; |