refactor(http): merge Request and Response from server and client

Request and Response are now visible from:
- hyper::{Request, Response}
- hyper::server::{Request, Response}
- hyper::client::{Request, Response}
They truly exist in the http module, but are re-exported to reduce the number of breaking changes.

request::new and response::new were renamed to ::from_wire to reduce confusion with Request::new
and Response::new. See issue #1126

Request now has an optional Body, because not all requests have bodies.
Use body_ref() to determine if a body exists.
Use body() to take the body, or construct one if no body exists.

Closes #1155

BREAKING CHANGE: Response::body() now consumes the response
This commit is contained in:
Nick Gonzales
2017-05-01 12:19:55 -06:00
parent 0de295670f
commit 864d3e27a4
11 changed files with 242 additions and 314 deletions

View File

@@ -24,13 +24,12 @@ use tokio_proto::streaming::Message;
use tokio_proto::streaming::pipeline::{Transport, Frame, ServerProto};
pub use tokio_service::{NewService, Service};
pub use self::request::Request;
pub use self::response::Response;
use http;
use http::response;
use http::request;
mod request;
mod response;
pub use http::response::Response;
pub use http::request::Request;
/// An instance of the HTTP protocol, and implementation of tokio-proto's
/// `ServerProto` trait.
@@ -284,7 +283,7 @@ impl From<Message<__ProtoRequest, http::TokioBody>> for Request {
Message::WithoutBody(head) => (head.0, http::Body::empty()),
Message::WithBody(head, body) => (head.0, body.into()),
};
request::new(None, head, body)
request::from_wire(None, head, body)
}
}
@@ -321,7 +320,7 @@ impl<T, B> Service for HttpService<T>
Message::WithoutBody(head) => (head.0, http::Body::empty()),
Message::WithBody(head, body) => (head.0, body.into()),
};
let req = request::new(Some(self.remote_addr), head, body);
let req = request::from_wire(Some(self.remote_addr), head, body);
self.inner.call(req).map(Into::into)
}
}