summaryrefslogtreecommitdiff
path: root/cli/http_body.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/http_body.rs')
-rw-r--r--cli/http_body.rs39
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");
-}