mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
upgrade: Tokio 0.2 (#3418)
This commit is contained in:
parent
df1665a8fc
commit
46d76a7562
18 changed files with 850 additions and 943 deletions
|
@ -7,7 +7,7 @@ use crate::ops::json_op;
|
|||
use crate::state::ThreadSafeState;
|
||||
use deno::*;
|
||||
use futures::future::FutureExt;
|
||||
use futures::future::TryFutureExt;
|
||||
use futures::StreamExt;
|
||||
use http::header::HeaderName;
|
||||
use http::header::HeaderValue;
|
||||
use http::Method;
|
||||
|
@ -56,32 +56,32 @@ pub fn op_fetch(
|
|||
}
|
||||
debug!("Before fetch {}", url);
|
||||
let state_ = state.clone();
|
||||
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(Box::new(body))),
|
||||
);
|
||||
let future = async move {
|
||||
let res = request.send().await?;
|
||||
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 json_res = json!({
|
||||
"bodyRid": rid,
|
||||
"status": status.as_u16(),
|
||||
"statusText": status.canonical_reason().unwrap_or(""),
|
||||
"headers": res_headers
|
||||
});
|
||||
let body = HttpBody::from(res.bytes_stream().boxed());
|
||||
let mut table = state_.lock_resource_table();
|
||||
let rid = table.add(
|
||||
"httpBody",
|
||||
Box::new(StreamResource::HttpBody(Box::new(body))),
|
||||
);
|
||||
|
||||
futures::future::ok(json_res)
|
||||
let json_res = json!({
|
||||
"bodyRid": rid,
|
||||
"status": status.as_u16(),
|
||||
"statusText": status.canonical_reason().unwrap_or(""),
|
||||
"headers": res_headers
|
||||
});
|
||||
|
||||
Ok(json_res)
|
||||
};
|
||||
|
||||
Ok(JsonOp::Async(future.boxed()))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue