diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2019-04-25 19:29:21 +0200 |
---|---|---|
committer | Bert Belder <bertbelder@gmail.com> | 2019-08-30 14:49:03 -0700 |
commit | 723284fd20bb320fc1c5c1c53d0617c1d4169c25 (patch) | |
tree | b5557bb39ed816d11523a4edb5f1711edc9930c3 /cli/file_fetcher.rs | |
parent | 840c4aa2b23cad129a16b9a57eeb9dcb50083c62 (diff) |
Use 'reqwest' to implement HTTP client (#2822)
Closes #2720
Diffstat (limited to 'cli/file_fetcher.rs')
-rw-r--r-- | cli/file_fetcher.rs | 25 |
1 files changed, 6 insertions, 19 deletions
diff --git a/cli/file_fetcher.rs b/cli/file_fetcher.rs index 97fd0ad8f..ae5454cd9 100644 --- a/cli/file_fetcher.rs +++ b/cli/file_fetcher.rs @@ -5,6 +5,7 @@ use crate::deno_error::ErrorKind; use crate::deno_error::GetErrorKind; use crate::disk_cache::DiskCache; use crate::http_util; +use crate::http_util::FetchOnceResult; use crate::msg; use crate::progress::Progress; use crate::tokio_util; @@ -12,7 +13,6 @@ use deno::ErrBox; use deno::ModuleSpecifier; use futures::future::Either; use futures::Future; -use http; use serde_json; use std; use std::collections::HashMap; @@ -21,7 +21,6 @@ use std::path::Path; use std::path::PathBuf; use std::result::Result; use std::str; -use std::str::FromStr; use std::sync::Arc; use std::sync::Mutex; use url; @@ -305,8 +304,6 @@ impl SourceFileFetcher { no_remote_fetch: bool, redirect_limit: i64, ) -> Box<SourceFileFuture> { - use crate::http_util::FetchOnceResult; - if redirect_limit < 0 { return Box::new(futures::future::err(too_many_redirects())); } @@ -342,20 +339,14 @@ impl SourceFileFetcher { } let download_job = self.progress.add("Download", &module_url.to_string()); - - let module_uri = url_into_uri(&module_url); - let dir = self.clone(); let module_url = module_url.clone(); // Single pass fetch, either yields code or yields redirect. - let f = - http_util::fetch_string_once(module_uri).and_then(move |r| match r { - FetchOnceResult::Redirect(uri) => { + let f = http_util::fetch_string_once(&module_url).and_then(move |r| { + match r { + FetchOnceResult::Redirect(new_module_url) => { // If redirects, update module_name and filename for next looped call. - let new_module_url = Url::parse(&uri.to_string()) - .expect("http::uri::Uri should be parseable as Url"); - dir .save_source_code_headers( &module_url, @@ -409,7 +400,8 @@ impl SourceFileFetcher { Either::B(futures::future::ok(source_file)) } - }); + } + }); Box::new(f) } @@ -539,11 +531,6 @@ fn filter_shebang(bytes: Vec<u8>) -> Vec<u8> { } } -fn url_into_uri(url: &url::Url) -> http::uri::Uri { - http::uri::Uri::from_str(&url.to_string()) - .expect("url::Url should be parseable as http::uri::Uri") -} - #[derive(Debug, Default)] /// Header metadata associated with a particular "symbolic" source code file. /// (the associated source code file might not be cached, while remaining |