1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-10-11 04:32:28 +00:00
actix-web/src/httpcodes.rs

32 lines
1.1 KiB
Rust
Raw Normal View History

2017-10-07 04:48:14 +00:00
//! Basic http responses
#![allow(non_upper_case_globals)]
use std::rc::Rc;
use http::StatusCode;
use task::Task;
use route::{Payload, RouteHandler};
2017-10-07 06:14:13 +00:00
use httpmessage::{Body, HttpRequest, HttpResponse, IntoHttpResponse};
2017-10-07 04:48:14 +00:00
pub struct StaticResponse(StatusCode);
pub const HTTPOk: StaticResponse = StaticResponse(StatusCode::OK);
pub const HTTPCreated: StaticResponse = StaticResponse(StatusCode::CREATED);
pub const HTTPNoContent: StaticResponse = StaticResponse(StatusCode::NO_CONTENT);
pub const HTTPBadRequest: StaticResponse = StaticResponse(StatusCode::BAD_REQUEST);
pub const HTTPNotFound: StaticResponse = StaticResponse(StatusCode::NOT_FOUND);
pub const HTTPMethodNotAllowed: StaticResponse = StaticResponse(StatusCode::METHOD_NOT_ALLOWED);
impl<S> RouteHandler<S> for StaticResponse {
fn handle(&self, req: HttpRequest, _: Option<Payload>, _: Rc<S>) -> Task
{
2017-10-07 06:36:36 +00:00
Task::reply(HttpResponse::new(req, self.0, Body::Empty))
2017-10-07 04:48:14 +00:00
}
}
2017-10-07 06:14:13 +00:00
impl IntoHttpResponse for StaticResponse {
fn into_response(self, req: HttpRequest) -> HttpResponse {
HttpResponse::new(req, self.0, Body::Empty)
2017-10-07 04:48:14 +00:00
}
}