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

@@ -22,19 +22,19 @@ pub use tokio_service::Service;
use header::{Headers, Host};
use http::{self, TokioBody};
use http::response;
use http::request;
use method::Method;
use self::pool::{Pool, Pooled};
use uri::{self, Uri};
pub use http::response::Response;
pub use http::request::Request;
pub use self::connect::{HttpConnector, Connect};
pub use self::request::Request;
pub use self::response::Response;
mod connect;
mod dns;
mod pool;
mod request;
mod response;
/// A Client to make outgoing HTTP requests.
// If the Connector is clone, then the Client can be clone easily.
@@ -198,8 +198,8 @@ where C: Connect,
});
FutureResponse(Box::new(req.map(|msg| {
match msg {
Message::WithoutBody(head) => response::new(head, None),
Message::WithBody(head, body) => response::new(head, Some(body.into())),
Message::WithoutBody(head) => response::from_wire(head, None),
Message::WithBody(head, body) => response::from_wire(head, Some(body.into())),
}
})))
}