From 2f45d5394a2f8a49442ff4798a4b1651c079f0ff Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Sat, 24 Feb 2018 11:53:55 -0800 Subject: [PATCH 1/2] feat(body): add `Body::is_empty()` method --- src/proto/body.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/proto/body.rs b/src/proto/body.rs index fedd9b09..f9211187 100644 --- a/src/proto/body.rs +++ b/src/proto/body.rs @@ -49,6 +49,22 @@ impl Body { let (tx, rx) = channel(); (tx.tx, rx) } + + /// Returns if this body was constructed via `Body::empty()`. + /// + /// # Note + /// + /// This does **not** detect if the body stream may be at the end, or + /// if the stream will not yield any chunks, in all cases. For instance, + /// a streaming body using `chunked` encoding is not able to tell if + /// there are more chunks immediately. + #[inline] + pub fn is_empty(&self) -> bool { + match self.0 { + Inner::Empty => true, + _ => false, + } + } } impl Default for Body { From 3fa191a2676feb86c91abf8dfcc8e63477980297 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Sat, 24 Feb 2018 12:16:25 -0800 Subject: [PATCH 2/2] feat(request): add `Request::body_mut()` method --- src/proto/request.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/proto/request.rs b/src/proto/request.rs index a344138c..c989b9c5 100644 --- a/src/proto/request.rs +++ b/src/proto/request.rs @@ -58,6 +58,10 @@ impl Request { #[inline] pub fn body_ref(&self) -> Option<&B> { self.body.as_ref() } + /// Get a mutable reference to the Request body. + #[inline] + pub fn body_mut(&mut self) -> &mut Option { &mut self.body } + #[doc(hidden)] #[inline] #[deprecated(since="0.11.12", note="This method will be gone in future versions.")]