fix(server): GET requests with no body have None instead of Empty
Closes #1373
This commit is contained in:
		| @@ -18,7 +18,7 @@ pub trait Dispatch { | ||||
|     type PollBody; | ||||
|     type RecvItem; | ||||
|     fn poll_msg(&mut self) -> Poll<Option<(Self::PollItem, Option<Self::PollBody>)>, ::Error>; | ||||
|     fn recv_msg(&mut self, msg: ::Result<(Self::RecvItem, Body)>) -> ::Result<()>; | ||||
|     fn recv_msg(&mut self, msg: ::Result<(Self::RecvItem, Option<Body>)>) -> ::Result<()>; | ||||
|     fn should_poll(&self) -> bool; | ||||
| } | ||||
|  | ||||
| @@ -60,9 +60,9 @@ where | ||||
|                         let body = if has_body { | ||||
|                             let (tx, rx) = super::Body::pair(); | ||||
|                             self.body_tx = Some(tx); | ||||
|                             rx | ||||
|                             Some(rx) | ||||
|                         } else { | ||||
|                             Body::empty() | ||||
|                             None | ||||
|                         }; | ||||
|                         self.dispatch.recv_msg(Ok((head, body))).expect("recv_msg with Ok shouldn't error"); | ||||
|                     }, | ||||
| @@ -253,7 +253,7 @@ where | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     fn recv_msg(&mut self, msg: ::Result<(Self::RecvItem, Body)>) -> ::Result<()> { | ||||
|     fn recv_msg(&mut self, msg: ::Result<(Self::RecvItem, Option<Body>)>) -> ::Result<()> { | ||||
|         let (msg, body) = msg?; | ||||
|         let req = super::request::from_wire(None, msg, body); | ||||
|         self.in_flight = Some(self.service.call(req)); | ||||
| @@ -300,10 +300,10 @@ where | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     fn recv_msg(&mut self, msg: ::Result<(Self::RecvItem, Body)>) -> ::Result<()> { | ||||
|     fn recv_msg(&mut self, msg: ::Result<(Self::RecvItem, Option<Body>)>) -> ::Result<()> { | ||||
|         match msg { | ||||
|             Ok((msg, body)) => { | ||||
|                 let res = super::response::from_wire(msg, Some(body)); | ||||
|                 let res = super::response::from_wire(msg, body); | ||||
|                 let cb = self.callback.take().expect("recv_msg without callback"); | ||||
|                 let _ = cb.send(Ok(res)); | ||||
|                 Ok(()) | ||||
|   | ||||
| @@ -168,16 +168,16 @@ impl<B> From<http::Request<B>> for Request<B> { | ||||
| } | ||||
|  | ||||
| /// Constructs a request using a received ResponseHead and optional body | ||||
| pub fn from_wire<B>(addr: Option<SocketAddr>, incoming: RequestHead, body: B) -> Request<B> { | ||||
| pub fn from_wire(addr: Option<SocketAddr>, incoming: RequestHead, body: Option<Body>) -> Request<Body> { | ||||
|     let MessageHead { version, subject: RequestLine(method, uri), headers } = incoming; | ||||
|  | ||||
|     Request::<B> { | ||||
|     Request { | ||||
|         method: method, | ||||
|         uri: uri, | ||||
|         headers: headers, | ||||
|         version: version, | ||||
|         remote_addr: addr, | ||||
|         body: Some(body), | ||||
|         body: body, | ||||
|         is_proxy: false, | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -219,8 +219,8 @@ impl From<Message<__ProtoRequest, proto::TokioBody>> for Request { | ||||
|     #[inline] | ||||
|     fn from(message: Message<__ProtoRequest, proto::TokioBody>) -> Request { | ||||
|         let (head, body) = match message { | ||||
|             Message::WithoutBody(head) => (head.0, proto::Body::empty()), | ||||
|             Message::WithBody(head, body) => (head.0, body.into()), | ||||
|             Message::WithoutBody(head) => (head.0, None), | ||||
|             Message::WithBody(head, body) => (head.0, Some(body.into())), | ||||
|         }; | ||||
|         request::from_wire(None, head, body) | ||||
|     } | ||||
| @@ -256,8 +256,8 @@ impl<T, B> Service for HttpService<T> | ||||
|     #[inline] | ||||
|     fn call(&self, message: Self::Request) -> Self::Future { | ||||
|         let (head, body) = match message { | ||||
|             Message::WithoutBody(head) => (head.0, proto::Body::empty()), | ||||
|             Message::WithBody(head, body) => (head.0, body.into()), | ||||
|             Message::WithoutBody(head) => (head.0, None), | ||||
|             Message::WithBody(head, body) => (head.0, Some(body.into())), | ||||
|         }; | ||||
|         let req = request::from_wire(Some(self.remote_addr), head, body); | ||||
|         self.inner.call(req).map(Into::into) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user