2017-10-07 06:48:14 +02:00
|
|
|
//! Basic http responses
|
2018-03-31 08:07:33 +02:00
|
|
|
#![allow(non_upper_case_globals, deprecated)]
|
2018-03-22 04:15:52 +01:00
|
|
|
use http::StatusCode;
|
2017-10-07 06:48:14 +02:00
|
|
|
|
2017-10-24 08:25:32 +02:00
|
|
|
use body::Body;
|
2018-03-22 04:15:52 +01:00
|
|
|
use error::Error;
|
2017-12-14 18:43:42 +01:00
|
|
|
use handler::{Reply, Handler, RouteHandler, Responder};
|
2017-10-15 07:52:38 +02:00
|
|
|
use httprequest::HttpRequest;
|
2017-10-24 08:25:32 +02:00
|
|
|
use httpresponse::{HttpResponse, HttpResponseBuilder};
|
2017-10-07 06:48:14 +02:00
|
|
|
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0", note="please use `HttpResponse::Ok()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpOk: StaticResponse = StaticResponse(StatusCode::OK);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0", note="please use `HttpResponse::Created()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpCreated: StaticResponse = StaticResponse(StatusCode::CREATED);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0", note="please use `HttpResponse::Accepted()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpAccepted: StaticResponse = StaticResponse(StatusCode::ACCEPTED);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0",
|
|
|
|
note="please use `HttpResponse::pNonAuthoritativeInformation()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpNonAuthoritativeInformation: StaticResponse =
|
|
|
|
StaticResponse(StatusCode::NON_AUTHORITATIVE_INFORMATION);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0", note="please use `HttpResponse::NoContent()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpNoContent: StaticResponse = StaticResponse(StatusCode::NO_CONTENT);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0", note="please use `HttpResponse::ResetContent()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpResetContent: StaticResponse = StaticResponse(StatusCode::RESET_CONTENT);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0", note="please use `HttpResponse::PartialContent()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpPartialContent: StaticResponse = StaticResponse(StatusCode::PARTIAL_CONTENT);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0", note="please use `HttpResponse::MultiStatus()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpMultiStatus: StaticResponse = StaticResponse(StatusCode::MULTI_STATUS);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0", note="please use `HttpResponse::AlreadyReported()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpAlreadyReported: StaticResponse = StaticResponse(StatusCode::ALREADY_REPORTED);
|
|
|
|
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0", note="please use `HttpResponse::MultipleChoices()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpMultipleChoices: StaticResponse = StaticResponse(StatusCode::MULTIPLE_CHOICES);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0", note="please use `HttpResponse::MovedPermanently()` instead")]
|
2018-03-07 21:54:25 +01:00
|
|
|
pub const HttpMovedPermanently: StaticResponse = StaticResponse(StatusCode::MOVED_PERMANENTLY);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0", note="please use `HttpResponse::Found()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpFound: StaticResponse = StaticResponse(StatusCode::FOUND);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0", note="please use `HttpResponse::SeeOther()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpSeeOther: StaticResponse = StaticResponse(StatusCode::SEE_OTHER);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0", note="please use `HttpResponse::NotModified()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpNotModified: StaticResponse = StaticResponse(StatusCode::NOT_MODIFIED);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0", note="please use `HttpResponse::UseProxy()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpUseProxy: StaticResponse = StaticResponse(StatusCode::USE_PROXY);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0", note="please use `HttpResponse::TemporaryRedirect()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpTemporaryRedirect: StaticResponse =
|
|
|
|
StaticResponse(StatusCode::TEMPORARY_REDIRECT);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0", note="please use `HttpResponse::PermanentRedirect()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpPermanentRedirect: StaticResponse =
|
|
|
|
StaticResponse(StatusCode::PERMANENT_REDIRECT);
|
|
|
|
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0", note="please use `HttpResponse::BadRequest()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpBadRequest: StaticResponse = StaticResponse(StatusCode::BAD_REQUEST);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0", note="please use `HttpResponse::Unauthorized()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpUnauthorized: StaticResponse = StaticResponse(StatusCode::UNAUTHORIZED);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0", note="please use `HttpResponse::PaymentRequired()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpPaymentRequired: StaticResponse = StaticResponse(StatusCode::PAYMENT_REQUIRED);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0", note="please use `HttpResponse::Forbidden()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpForbidden: StaticResponse = StaticResponse(StatusCode::FORBIDDEN);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0", note="please use `HttpResponse::NotFound()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpNotFound: StaticResponse = StaticResponse(StatusCode::NOT_FOUND);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0", note="please use `HttpResponse::MethodNotAllowed()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpMethodNotAllowed: StaticResponse =
|
|
|
|
StaticResponse(StatusCode::METHOD_NOT_ALLOWED);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0", note="please use `HttpResponse::NotAcceptable()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpNotAcceptable: StaticResponse = StaticResponse(StatusCode::NOT_ACCEPTABLE);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0",
|
|
|
|
note="please use `HttpResponse::ProxyAuthenticationRequired()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpProxyAuthenticationRequired: StaticResponse =
|
|
|
|
StaticResponse(StatusCode::PROXY_AUTHENTICATION_REQUIRED);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0", note="please use `HttpResponse::RequestTimeout()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpRequestTimeout: StaticResponse = StaticResponse(StatusCode::REQUEST_TIMEOUT);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0", note="please use `HttpResponse::Conflict()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpConflict: StaticResponse = StaticResponse(StatusCode::CONFLICT);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0", note="please use `HttpResponse::Gone()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpGone: StaticResponse = StaticResponse(StatusCode::GONE);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0", note="please use `HttpResponse::LengthRequired()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpLengthRequired: StaticResponse = StaticResponse(StatusCode::LENGTH_REQUIRED);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0", note="please use `HttpResponse::PreconditionFailed()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpPreconditionFailed: StaticResponse =
|
|
|
|
StaticResponse(StatusCode::PRECONDITION_FAILED);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0", note="please use `HttpResponse::PayloadTooLarge()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpPayloadTooLarge: StaticResponse = StaticResponse(StatusCode::PAYLOAD_TOO_LARGE);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0", note="please use `HttpResponse::UriTooLong()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpUriTooLong: StaticResponse = StaticResponse(StatusCode::URI_TOO_LONG);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0",
|
|
|
|
note="please use `HttpResponse::UnsupportedMediaType()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpUnsupportedMediaType: StaticResponse =
|
|
|
|
StaticResponse(StatusCode::UNSUPPORTED_MEDIA_TYPE);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0",
|
|
|
|
note="please use `HttpResponse::RangeNotSatisfiable()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpRangeNotSatisfiable: StaticResponse =
|
|
|
|
StaticResponse(StatusCode::RANGE_NOT_SATISFIABLE);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0", note="please use `HttpResponse::ExpectationFailed()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpExpectationFailed: StaticResponse =
|
|
|
|
StaticResponse(StatusCode::EXPECTATION_FAILED);
|
|
|
|
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0",
|
|
|
|
note="please use `HttpResponse::InternalServerError()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpInternalServerError: StaticResponse =
|
|
|
|
StaticResponse(StatusCode::INTERNAL_SERVER_ERROR);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0", note="please use `HttpResponse::NotImplemented()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpNotImplemented: StaticResponse = StaticResponse(StatusCode::NOT_IMPLEMENTED);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0", note="please use `HttpResponse::BadGateway()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpBadGateway: StaticResponse = StaticResponse(StatusCode::BAD_GATEWAY);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0", note="please use `HttpResponse::ServiceUnavailable()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpServiceUnavailable: StaticResponse =
|
|
|
|
StaticResponse(StatusCode::SERVICE_UNAVAILABLE);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0", note="please use `HttpResponse::GatewayTimeout()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpGatewayTimeout: StaticResponse =
|
|
|
|
StaticResponse(StatusCode::GATEWAY_TIMEOUT);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0",
|
|
|
|
note="please use `HttpResponse::VersionNotSupported()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpVersionNotSupported: StaticResponse =
|
|
|
|
StaticResponse(StatusCode::HTTP_VERSION_NOT_SUPPORTED);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0",
|
|
|
|
note="please use `HttpResponse::VariantAlsoNegotiates()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpVariantAlsoNegotiates: StaticResponse =
|
|
|
|
StaticResponse(StatusCode::VARIANT_ALSO_NEGOTIATES);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0",
|
|
|
|
note="please use `HttpResponse::InsufficientStorage()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpInsufficientStorage: StaticResponse =
|
|
|
|
StaticResponse(StatusCode::INSUFFICIENT_STORAGE);
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0", note="please use `HttpResponse::LoopDetected()` instead")]
|
2018-03-02 04:12:59 +01:00
|
|
|
pub const HttpLoopDetected: StaticResponse = StaticResponse(StatusCode::LOOP_DETECTED);
|
|
|
|
|
2017-10-07 06:48:14 +02:00
|
|
|
|
2018-03-31 08:07:33 +02:00
|
|
|
#[deprecated(since="0.5.0", note="please use `HttpResponse` instead")]
|
2018-01-11 20:14:18 +01:00
|
|
|
#[derive(Copy, Clone, Debug)]
|
2017-10-08 06:48:00 +02:00
|
|
|
pub struct StaticResponse(StatusCode);
|
|
|
|
|
|
|
|
impl StaticResponse {
|
2017-11-27 07:31:29 +01:00
|
|
|
pub fn build(&self) -> HttpResponseBuilder {
|
|
|
|
HttpResponse::build(self.0)
|
2017-10-11 01:03:32 +02:00
|
|
|
}
|
2018-03-23 05:14:57 +01:00
|
|
|
pub fn build_from<S>(&self, req: &HttpRequest<S>) -> HttpResponseBuilder {
|
|
|
|
req.build_response(self.0)
|
|
|
|
}
|
2017-10-11 01:03:32 +02:00
|
|
|
pub fn with_reason(self, reason: &'static str) -> HttpResponse {
|
2018-03-31 08:07:33 +02:00
|
|
|
let mut resp = HttpResponse::new(self.0);
|
2017-10-11 01:03:32 +02:00
|
|
|
resp.set_reason(reason);
|
|
|
|
resp
|
2017-10-08 06:48:00 +02:00
|
|
|
}
|
2017-10-24 08:25:32 +02:00
|
|
|
pub fn with_body<B: Into<Body>>(self, body: B) -> HttpResponse {
|
2018-03-31 08:07:33 +02:00
|
|
|
HttpResponse::with_body(self.0, body.into())
|
2017-10-16 00:52:52 +02:00
|
|
|
}
|
2017-10-08 06:48:00 +02:00
|
|
|
}
|
|
|
|
|
2017-12-04 23:07:53 +01:00
|
|
|
impl<S> Handler<S> for StaticResponse {
|
|
|
|
type Result = HttpResponse;
|
|
|
|
|
2017-12-26 18:00:45 +01:00
|
|
|
fn handle(&mut self, _: HttpRequest<S>) -> HttpResponse {
|
2018-03-31 08:07:33 +02:00
|
|
|
HttpResponse::new(self.0)
|
2017-12-04 23:07:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-07 06:48:14 +02:00
|
|
|
impl<S> RouteHandler<S> for StaticResponse {
|
2017-12-26 18:00:45 +01:00
|
|
|
fn handle(&mut self, _: HttpRequest<S>) -> Reply {
|
2018-03-31 08:07:33 +02:00
|
|
|
Reply::response(HttpResponse::new(self.0))
|
2017-10-07 06:48:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-14 18:43:42 +01:00
|
|
|
impl Responder for StaticResponse {
|
2017-12-03 23:22:04 +01:00
|
|
|
type Item = HttpResponse;
|
2018-03-22 04:15:52 +01:00
|
|
|
type Error = Error;
|
2017-12-03 23:22:04 +01:00
|
|
|
|
2018-03-22 04:15:52 +01:00
|
|
|
fn respond_to(self, _: HttpRequest) -> Result<HttpResponse, Error> {
|
2018-03-31 08:07:33 +02:00
|
|
|
Ok(self.build().finish())
|
2017-12-03 01:37:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-11 01:03:32 +02:00
|
|
|
impl From<StaticResponse> for HttpResponse {
|
|
|
|
fn from(st: StaticResponse) -> Self {
|
2018-03-31 08:07:33 +02:00
|
|
|
HttpResponse::new(st.0)
|
2017-10-07 06:48:14 +02:00
|
|
|
}
|
|
|
|
}
|
2017-10-14 19:01:53 +02:00
|
|
|
|
2018-01-03 08:43:17 +01:00
|
|
|
impl From<StaticResponse> for Reply {
|
|
|
|
fn from(st: StaticResponse) -> Self {
|
2018-03-31 08:07:33 +02:00
|
|
|
HttpResponse::new(st.0).into()
|
2018-01-03 08:43:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-28 23:23:42 +01:00
|
|
|
macro_rules! STATIC_RESP {
|
|
|
|
($name:ident, $status:expr) => {
|
|
|
|
#[allow(non_snake_case)]
|
|
|
|
pub fn $name() -> HttpResponseBuilder {
|
|
|
|
HttpResponse::build($status)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl HttpResponse {
|
|
|
|
STATIC_RESP!(Ok, StatusCode::OK);
|
|
|
|
STATIC_RESP!(Created, StatusCode::CREATED);
|
2018-03-31 08:07:33 +02:00
|
|
|
STATIC_RESP!(Accepted, StatusCode::ACCEPTED);
|
|
|
|
STATIC_RESP!(NonAuthoritativeInformation, StatusCode::NON_AUTHORITATIVE_INFORMATION);
|
|
|
|
|
2017-11-28 23:23:42 +01:00
|
|
|
STATIC_RESP!(NoContent, StatusCode::NO_CONTENT);
|
2018-03-31 08:07:33 +02:00
|
|
|
STATIC_RESP!(ResetContent, StatusCode::RESET_CONTENT);
|
|
|
|
STATIC_RESP!(PartialContent, StatusCode::PARTIAL_CONTENT);
|
|
|
|
STATIC_RESP!(MultiStatus, StatusCode::MULTI_STATUS);
|
|
|
|
STATIC_RESP!(AlreadyReported, StatusCode::ALREADY_REPORTED);
|
2017-11-28 23:23:42 +01:00
|
|
|
|
|
|
|
STATIC_RESP!(MultipleChoices, StatusCode::MULTIPLE_CHOICES);
|
|
|
|
STATIC_RESP!(MovedPermanenty, StatusCode::MOVED_PERMANENTLY);
|
|
|
|
STATIC_RESP!(Found, StatusCode::FOUND);
|
|
|
|
STATIC_RESP!(SeeOther, StatusCode::SEE_OTHER);
|
|
|
|
STATIC_RESP!(NotModified, StatusCode::NOT_MODIFIED);
|
|
|
|
STATIC_RESP!(UseProxy, StatusCode::USE_PROXY);
|
|
|
|
STATIC_RESP!(TemporaryRedirect, StatusCode::TEMPORARY_REDIRECT);
|
|
|
|
STATIC_RESP!(PermanentRedirect, StatusCode::PERMANENT_REDIRECT);
|
|
|
|
|
|
|
|
STATIC_RESP!(BadRequest, StatusCode::BAD_REQUEST);
|
|
|
|
STATIC_RESP!(NotFound, StatusCode::NOT_FOUND);
|
|
|
|
STATIC_RESP!(Unauthorized, StatusCode::UNAUTHORIZED);
|
|
|
|
STATIC_RESP!(PaymentRequired, StatusCode::PAYMENT_REQUIRED);
|
|
|
|
STATIC_RESP!(Forbidden, StatusCode::FORBIDDEN);
|
|
|
|
STATIC_RESP!(MethodNotAllowed, StatusCode::METHOD_NOT_ALLOWED);
|
|
|
|
STATIC_RESP!(NotAcceptable, StatusCode::NOT_ACCEPTABLE);
|
|
|
|
STATIC_RESP!(ProxyAuthenticationRequired, StatusCode::PROXY_AUTHENTICATION_REQUIRED);
|
|
|
|
STATIC_RESP!(RequestTimeout, StatusCode::REQUEST_TIMEOUT);
|
|
|
|
STATIC_RESP!(Conflict, StatusCode::CONFLICT);
|
|
|
|
STATIC_RESP!(Gone, StatusCode::GONE);
|
|
|
|
STATIC_RESP!(LengthRequired, StatusCode::LENGTH_REQUIRED);
|
|
|
|
STATIC_RESP!(PreconditionFailed, StatusCode::PRECONDITION_FAILED);
|
|
|
|
STATIC_RESP!(PayloadTooLarge, StatusCode::PAYLOAD_TOO_LARGE);
|
|
|
|
STATIC_RESP!(UriTooLong, StatusCode::URI_TOO_LONG);
|
2018-03-31 08:07:33 +02:00
|
|
|
STATIC_RESP!(UnsupportedMediaType, StatusCode::UNSUPPORTED_MEDIA_TYPE);
|
|
|
|
STATIC_RESP!(RangeNotSatisfiable, StatusCode::RANGE_NOT_SATISFIABLE);
|
2017-11-28 23:23:42 +01:00
|
|
|
STATIC_RESP!(ExpectationFailed, StatusCode::EXPECTATION_FAILED);
|
|
|
|
|
|
|
|
STATIC_RESP!(InternalServerError, StatusCode::INTERNAL_SERVER_ERROR);
|
2018-03-31 08:07:33 +02:00
|
|
|
STATIC_RESP!(NotImplemented, StatusCode::NOT_IMPLEMENTED);
|
|
|
|
STATIC_RESP!(BadGateway, StatusCode::BAD_GATEWAY);
|
|
|
|
STATIC_RESP!(ServiceUnavailable, StatusCode::SERVICE_UNAVAILABLE);
|
|
|
|
STATIC_RESP!(GatewayTimeout, StatusCode::GATEWAY_TIMEOUT);
|
|
|
|
STATIC_RESP!(VersionNotSupported, StatusCode::HTTP_VERSION_NOT_SUPPORTED);
|
|
|
|
STATIC_RESP!(VariantAlsoNegotiates, StatusCode::VARIANT_ALSO_NEGOTIATES);
|
|
|
|
STATIC_RESP!(InsufficientStorage, StatusCode::INSUFFICIENT_STORAGE);
|
|
|
|
STATIC_RESP!(LoopDetected, StatusCode::LOOP_DETECTED);
|
2017-11-28 23:23:42 +01:00
|
|
|
}
|
2017-10-14 19:01:53 +02:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use http::StatusCode;
|
2018-03-31 02:31:18 +02:00
|
|
|
use super::{HttpOk, HttpBadRequest, Body, HttpResponse};
|
2017-10-14 19:01:53 +02:00
|
|
|
|
|
|
|
#[test]
|
2017-11-27 07:31:29 +01:00
|
|
|
fn test_build() {
|
2018-03-31 08:07:33 +02:00
|
|
|
let resp = HttpOk.build().body(Body::Empty);
|
2017-10-14 19:01:53 +02:00
|
|
|
assert_eq!(resp.status(), StatusCode::OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_response() {
|
2018-03-31 02:31:18 +02:00
|
|
|
let resp: HttpResponse = HttpOk.into();
|
2017-10-14 19:01:53 +02:00
|
|
|
assert_eq!(resp.status(), StatusCode::OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_from() {
|
2018-03-31 02:31:18 +02:00
|
|
|
let resp: HttpResponse = HttpOk.into();
|
2017-10-14 19:01:53 +02:00
|
|
|
assert_eq!(resp.status(), StatusCode::OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_with_reason() {
|
2018-03-31 02:31:18 +02:00
|
|
|
let resp: HttpResponse = HttpOk.into();
|
2017-12-13 20:10:03 +01:00
|
|
|
assert_eq!(resp.reason(), "OK");
|
2017-10-14 19:01:53 +02:00
|
|
|
|
2018-03-31 02:31:18 +02:00
|
|
|
let resp = HttpBadRequest.with_reason("test");
|
2017-10-14 19:01:53 +02:00
|
|
|
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
|
|
|
|
assert_eq!(resp.reason(), "test");
|
|
|
|
}
|
|
|
|
}
|