diff options
Diffstat (limited to 'cli/ops/fetch.rs')
-rw-r--r-- | cli/ops/fetch.rs | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/cli/ops/fetch.rs b/cli/ops/fetch.rs index a1c0fe29c..25cf99812 100644 --- a/cli/ops/fetch.rs +++ b/cli/ops/fetch.rs @@ -6,11 +6,11 @@ use crate::http_util::get_client; use crate::ops::json_op; use crate::state::ThreadSafeState; use deno::*; +use futures::future::FutureExt; +use futures::future::TryFutureExt; use http::header::HeaderName; use http::header::HeaderValue; use http::Method; -use hyper; -use hyper::rt::Future; use std; use std::convert::From; @@ -56,26 +56,32 @@ pub fn op_fetch( } debug!("Before fetch {}", url); let state_ = state.clone(); - let future = request.send().map_err(ErrBox::from).and_then(move |res| { - let status = res.status(); - let mut res_headers = Vec::new(); - for (key, val) in res.headers().iter() { - res_headers.push((key.to_string(), val.to_str().unwrap().to_owned())); - } + let future = futures::compat::Compat01As03::new(request.send()) + .map_err(ErrBox::from) + .and_then(move |res| { + debug!("Fetch response {}", url); + let status = res.status(); + let mut res_headers = Vec::new(); + for (key, val) in res.headers().iter() { + res_headers.push((key.to_string(), val.to_str().unwrap().to_owned())); + } - let body = HttpBody::from(res.into_body()); - let mut table = state_.lock_resource_table(); - let rid = table.add("httpBody", Box::new(StreamResource::HttpBody(body))); + let body = HttpBody::from(res.into_body()); + let mut table = state_.lock_resource_table(); + let rid = table.add( + "httpBody", + Box::new(StreamResource::HttpBody(Box::new(body))), + ); - let json_res = json!({ - "bodyRid": rid, - "status": status.as_u16(), - "statusText": status.canonical_reason().unwrap_or(""), - "headers": res_headers - }); + let json_res = json!({ + "bodyRid": rid, + "status": status.as_u16(), + "statusText": status.canonical_reason().unwrap_or(""), + "headers": res_headers + }); - futures::future::ok(json_res) - }); + futures::future::ok(json_res) + }); - Ok(JsonOp::Async(Box::new(future))) + Ok(JsonOp::Async(future.boxed())) } |