Skip to main content

tower_embed_core/
response.rs

1//! Standard HTTP responses for common status codes.
2
3use crate::Body;
4
5/// The standard HTTP response for Not Found (404).
6pub fn not_found() -> http::Response<Body> {
7    http::Response::builder()
8        .status(http::StatusCode::NOT_FOUND)
9        .body(Body::empty())
10        .unwrap()
11}
12
13/// The standard HTTP response for Not Modified (304).
14pub fn not_modified() -> http::Response<Body> {
15    http::Response::builder()
16        .status(http::StatusCode::NOT_MODIFIED)
17        .body(Body::empty())
18        .unwrap()
19}
20
21/// The standard HTTP response for Method Not Allowed (405).
22pub fn method_not_allowed() -> http::Response<Body> {
23    http::Response::builder()
24        .header(
25            http::header::ALLOW,
26            http::HeaderValue::from_static("GET, HEAD"),
27        )
28        .status(http::StatusCode::METHOD_NOT_ALLOWED)
29        .body(Body::empty())
30        .unwrap()
31}
32
33/// The standard HTTP response for Internal Server Error (500).
34pub fn internal_server_error() -> http::Response<Body> {
35    http::Response::builder()
36        .status(http::StatusCode::INTERNAL_SERVER_ERROR)
37        .body(Body::empty())
38        .unwrap()
39}