提交 7c128df4 编写于 作者: R Ryan Dahl

Use lazy_static for HttpsConnector

And rename net.rs to http.rs

Share HTTP connection.
上级 7fb28219
......@@ -47,6 +47,7 @@ main_extern = [
"$rust_build:hyper",
"$rust_build:hyper_rustls",
"$rust_build:futures",
"$rust_build:lazy_static",
"$rust_build:libc",
"$rust_build:log",
"$rust_build:ring",
......
......@@ -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(()),
......
......@@ -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",
))
}
......
// 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)
......
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册