fix unreachable code if polling async Body created from a single buffer
This commit is contained in:
		| @@ -1,4 +1,4 @@ | |||||||
| use std::fmt; | use std::{fmt, mem}; | ||||||
|  |  | ||||||
| use futures::{Stream, Poll, Async}; | use futures::{Stream, Poll, Async}; | ||||||
| use bytes::{Buf, Bytes}; | use bytes::{Buf, Bytes}; | ||||||
| @@ -17,7 +17,19 @@ enum Inner { | |||||||
| impl Body { | impl Body { | ||||||
|     fn poll_inner(&mut self) -> &mut ::hyper::Body { |     fn poll_inner(&mut self) -> &mut ::hyper::Body { | ||||||
|         match self.inner { |         match self.inner { | ||||||
|             Inner::Hyper(ref mut body) => body, |             Inner::Hyper(ref mut body) => return body, | ||||||
|  |             Inner::Reusable(_) => (), | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         let bytes = match mem::replace(&mut self.inner, Inner::Reusable(Bytes::new())) { | ||||||
|  |             Inner::Reusable(bytes) => bytes, | ||||||
|  |             Inner::Hyper(_) => unreachable!(), | ||||||
|  |         }; | ||||||
|  |  | ||||||
|  |         self.inner = Inner::Hyper(bytes.into()); | ||||||
|  |  | ||||||
|  |         match self.inner { | ||||||
|  |             Inner::Hyper(ref mut body) => return body, | ||||||
|             Inner::Reusable(_) => unreachable!(), |             Inner::Reusable(_) => unreachable!(), | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @@ -56,8 +68,7 @@ impl Body { | |||||||
|             Inner::Reusable(chunk) => (Some(chunk.clone()), chunk.into()), |             Inner::Reusable(chunk) => (Some(chunk.clone()), chunk.into()), | ||||||
|             Inner::Hyper(b) => (None, b), |             Inner::Hyper(b) => (None, b), | ||||||
|         } |         } | ||||||
| } |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| impl Stream for Body { | impl Stream for Body { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user