diff options
Diffstat (limited to 'src/http.rs')
-rw-r--r-- | src/http.rs | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/http.rs b/src/http.rs index 5907b35ed..3b5ede10e 100644 --- a/src/http.rs +++ b/src/http.rs @@ -1,10 +1,12 @@ // Copyright 2018 the Deno authors. All rights reserved. MIT license. use errors::DenoResult; +use tokio_util; use futures::Future; use futures::Stream; use hyper; +use hyper::client::Client; use hyper::client::HttpConnector; use hyper::Uri; use hyper_rustls; @@ -29,21 +31,24 @@ pub fn get_client() -> Client<Connector, hyper::Body> { pub fn fetch_sync_string(module_name: &str) -> DenoResult<String> { let url = module_name.parse::<Uri>().unwrap(); let client = get_client(); - - // TODO Use Deno's RT - let mut rt = Runtime::new().unwrap(); - let body = rt.block_on( - client - .get(url) - .and_then(|response| response.into_body().concat2()), - )?; + let future = client + .get(url) + .and_then(|response| response.into_body().concat2()); + let body = tokio_util::block_on(future)?; Ok(String::from_utf8(body.to_vec()).unwrap()) } #[test] fn test_fetch_sync_string() { // Relies on external http server. See tools/http_server.py - let p = fetch_sync_string("http://localhost:4545/package.json").unwrap(); - println!("package.json len {}", p.len()); - assert!(p.len() > 1); + use futures; + + tokio_util::init(|| { + tokio_util::block_on(futures::future::lazy(|| -> DenoResult<()> { + let p = fetch_sync_string("http://127.0.0.1:4545/package.json")?; + println!("package.json len {}", p.len()); + assert!(p.len() > 1); + Ok(()) + })).unwrap(); + }); } |