mod builder;
mod responder;
pub use self::builder::Builder;
pub use self::responder::Responder;
use std::fmt;
use futures::{Future, IntoFuture};
use futures::future::{self, FutureResult};
use hyper;
use http::StatusCode;
use http::header::Headers;
pub struct Response {
inner: hyper::Response<hyper::Body>,
}
impl Response {
pub fn new() -> Self {
Default::default()
}
pub fn build() -> Builder {
Default::default()
}
pub fn with<R: Responder>(responder: R) -> R::Result
where
<R::Result as IntoFuture>::Error: fmt::Debug + Send + 'static,
{
responder.to_response()
}
pub(crate) fn into_hyper_response(self) -> hyper::Response<hyper::Body> {
self.inner
}
#[inline]
pub fn status(&self) -> StatusCode {
self.inner.status()
}
#[inline]
pub fn set_status(&mut self, status: StatusCode) {
self.inner.set_status(status);
}
pub fn body(self) -> hyper::Body {
self.inner.body()
}
#[inline]
pub fn set_body<B: Into<hyper::Body>>(&mut self, body: B) {
self.inner.set_body(body.into());
}
#[inline]
pub fn headers_mut(&mut self) -> &mut Headers {
self.inner.headers_mut()
}
}
impl Default for Response {
fn default() -> Self {
Self {
inner: hyper::Response::new(),
}
}
}
impl IntoFuture for Response {
type Item = Self;
type Error = hyper::Error;
type Future = FutureResult<Self::Item, Self::Error>;
#[inline]
fn into_future(self) -> Self::Future {
future::ok(self)
}
}
#[deprecated(since = "0.0.6", note = "use BoxFuture<Response, _> instead")]
pub type BoxFutureResponse<E = hyper::Error> = Box<Future<Item = Response, Error = E>>;