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/http_body.rs | |
parent | 840c4aa2b23cad129a16b9a57eeb9dcb50083c62 (diff) |
Use 'reqwest' to implement HTTP client (#2822)
Closes #2720
Diffstat (limited to 'cli/http_body.rs')
-rw-r--r-- | cli/http_body.rs | 39 |
1 files changed, 8 insertions, 31 deletions
diff --git a/cli/http_body.rs b/cli/http_body.rs index 235463ff1..c03dfd637 100644 --- a/cli/http_body.rs +++ b/cli/http_body.rs @@ -1,27 +1,27 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. +use futures::stream::Stream; use futures::Async; use futures::Poll; -use hyper::body::Payload; -use hyper::Body; -use hyper::Chunk; +use reqwest::r#async::Chunk; +use reqwest::r#async::Decoder; use std::cmp::min; use std::io; use std::io::Read; use tokio::io::AsyncRead; -/// Wraps `hyper::Body` so that it can be exposed as an `AsyncRead` and integrated +/// Wraps `reqwest::Decoder` so that it can be exposed as an `AsyncRead` and integrated /// into resources more easily. pub struct HttpBody { - body: Body, + decoder: Decoder, chunk: Option<Chunk>, pos: usize, } impl HttpBody { - pub fn from(body: Body) -> Self { + pub fn from(body: Decoder) -> Self { Self { - body, + decoder: body, chunk: None, pos: 0, } @@ -59,7 +59,7 @@ impl AsyncRead for HttpBody { assert_eq!(self.pos, 0); } - let p = self.body.poll_data(); + let p = self.decoder.poll(); match p { Err(e) => Err( // TODO Need to map hyper::Error into std::io::Error. @@ -87,26 +87,3 @@ impl AsyncRead for HttpBody { } } } - -#[test] -fn test_body_async_read() { - use std::str::from_utf8; - let body = Body::from("hello world"); - let mut body = HttpBody::from(body); - - let buf = &mut [0, 0, 0, 0, 0]; - let r = body.poll_read(buf); - assert!(r.is_ok()); - assert_eq!(r.unwrap(), Async::Ready(5)); - assert_eq!(from_utf8(buf).unwrap(), "hello"); - - let r = body.poll_read(buf); - assert!(r.is_ok()); - assert_eq!(r.unwrap(), Async::Ready(5)); - assert_eq!(from_utf8(buf).unwrap(), " worl"); - - let r = body.poll_read(buf); - assert!(r.is_ok()); - assert_eq!(r.unwrap(), Async::Ready(1)); - assert_eq!(from_utf8(&buf[0..1]).unwrap(), "d"); -} |