Skip to content

Commit 1281620

Browse files
committed
construct bodies from impl Read instead of impl BufRead
1 parent f77c653 commit 1281620

File tree

3 files changed

+6
-41
lines changed

3 files changed

+6
-41
lines changed

src/body.rs

+6-17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use futures_lite::{io, prelude::*, ready};
1+
use futures_lite::{io, prelude::*, ready, AsyncRead as Read};
22
use serde::{de::DeserializeOwned, Serialize};
33

44
use std::fmt::{self, Debug};
@@ -12,7 +12,7 @@ pin_project_lite::pin_project! {
1212
/// A streaming HTTP body.
1313
///
1414
/// `Body` represents the HTTP body of both `Request` and `Response`. It's completely
15-
/// streaming, and implements `AsyncBufRead` to make reading from it both convenient and
15+
/// streaming, and implements `AsyncRead` to make reading from it both convenient and
1616
/// performant.
1717
///
1818
/// Both `Request` and `Response` take `Body` by `Into<Body>`, which means that passing string
@@ -53,7 +53,7 @@ pin_project_lite::pin_project! {
5353
/// and not rely on the fallback mechanisms. However, they're still there if you need them.
5454
pub struct Body {
5555
#[pin]
56-
reader: Box<dyn AsyncBufRead + Unpin + Send + Sync + 'static>,
56+
reader: Box<dyn Read + Unpin + Send + Sync + 'static>,
5757
mime: Mime,
5858
length: Option<usize>,
5959
bytes_read: usize
@@ -103,7 +103,7 @@ impl Body {
103103
/// req.set_body(Body::from_reader(cursor, Some(len)));
104104
/// ```
105105
pub fn from_reader(
106-
reader: impl AsyncBufRead + Unpin + Send + Sync + 'static,
106+
reader: impl Read + Unpin + Send + Sync + 'static,
107107
len: Option<usize>,
108108
) -> Self {
109109
Self {
@@ -127,7 +127,7 @@ impl Body {
127127
/// let body = Body::from_reader(cursor, None);
128128
/// let _ = body.into_reader();
129129
/// ```
130-
pub fn into_reader(self) -> Box<dyn AsyncBufRead + Unpin + Send + Sync + 'static> {
130+
pub fn into_reader(self) -> Box<dyn Read + Unpin + Send + Sync + 'static> {
131131
self.reader
132132
}
133133

@@ -383,7 +383,7 @@ impl Body {
383383
Ok(Self {
384384
mime,
385385
length: Some(len as usize),
386-
reader: Box::new(io::BufReader::new(file)),
386+
reader: Box::new(file),
387387
bytes_read: 0,
388388
})
389389
}
@@ -483,17 +483,6 @@ impl AsyncRead for Body {
483483
}
484484
}
485485

486-
impl AsyncBufRead for Body {
487-
#[allow(missing_doc_code_examples)]
488-
fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<&'_ [u8]>> {
489-
self.project().reader.poll_fill_buf(cx)
490-
}
491-
492-
fn consume(mut self: Pin<&mut Self>, amt: usize) {
493-
Pin::new(&mut self.reader).consume(amt)
494-
}
495-
}
496-
497486
/// Look at first few bytes of a file to determine the mime type.
498487
/// This is used for various binary formats such as images and videos.
499488
#[cfg(all(feature = "fs", not(target_os = "unknown")))]

src/request.rs

-12
Original file line numberDiff line numberDiff line change
@@ -892,18 +892,6 @@ impl AsyncRead for Request {
892892
}
893893
}
894894

895-
impl AsyncBufRead for Request {
896-
#[allow(missing_doc_code_examples)]
897-
fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<&'_ [u8]>> {
898-
let this = self.project();
899-
this.body.poll_fill_buf(cx)
900-
}
901-
902-
fn consume(mut self: Pin<&mut Self>, amt: usize) {
903-
Pin::new(&mut self.body).consume(amt)
904-
}
905-
}
906-
907895
impl AsRef<Headers> for Request {
908896
fn as_ref(&self) -> &Headers {
909897
&self.headers

src/response.rs

-12
Original file line numberDiff line numberDiff line change
@@ -603,18 +603,6 @@ impl AsyncRead for Response {
603603
}
604604
}
605605

606-
impl AsyncBufRead for Response {
607-
#[allow(missing_doc_code_examples)]
608-
fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<&'_ [u8]>> {
609-
let this = self.project();
610-
this.body.poll_fill_buf(cx)
611-
}
612-
613-
fn consume(mut self: Pin<&mut Self>, amt: usize) {
614-
Pin::new(&mut self.body).consume(amt)
615-
}
616-
}
617-
618606
impl AsRef<Headers> for Response {
619607
fn as_ref(&self) -> &Headers {
620608
&self.headers

0 commit comments

Comments
 (0)