From 8f9a942cb911ed017eb128e9fbeb6f9a48e69601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sun, 17 Nov 2019 01:17:47 +0100 Subject: Use futures 0.3 API (#3358) --- cli/ops/fetch.rs | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) (limited to 'cli/ops/fetch.rs') 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())) } -- cgit v1.2.3