poem_openapi/response/
static_file.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
use poem::{web::StaticFileResponse, Body};

use crate::{
    payload::{Binary, Payload},
    registry::{MetaHeader, MetaMediaType, MetaResponse, MetaResponses, Registry},
    types::Type,
    ApiResponse,
};

const ETAG_DESCRIPTION: &str = r#"The ETag (or entity tag) HTTP response header is an identifier for a specific version of a resource. It lets caches be more efficient and save bandwidth, as a web server does not need to resend a full response if the content was not changed. Additionally, etags help to prevent simultaneous updates of a resource from overwriting each other ("mid-air collisions")."#;
const LAST_MODIFIED_DESCRIPTION: &str = r#"The Last-Modified response HTTP header contains a date and time when the origin server believes the resource was last modified. It is used as a validator to determine if the resource is the same as the previously stored one. Less accurate than an ETag header, it is a fallback mechanism. Conditional requests containing If-Modified-Since or If-Unmodified-Since headers make use of this field."#;
const CONTENT_TYPE_DESCRIPTION: &str = r#"The Content-Type representation header is used to indicate the original media type of the resource (prior to any content encoding applied for sending)."#;

impl ApiResponse for StaticFileResponse {
    fn meta() -> MetaResponses {
        MetaResponses {
            responses: vec![
                MetaResponse {
                    description: "",
                    status: Some(200),
                    content: vec![MetaMediaType {
                        content_type: Binary::<Body>::CONTENT_TYPE,
                        schema: Binary::<Body>::schema_ref(),
                    }],
                    headers: vec![MetaHeader {
                        name: "etag".to_string(),
                        description: Some(ETAG_DESCRIPTION.to_string()),
                        required: false,
                        deprecated: false,
                        schema: String::schema_ref(),
                    }, MetaHeader {
                        name: "last-modified".to_string(),
                        description: Some(LAST_MODIFIED_DESCRIPTION.to_string()),
                        required: false,
                        deprecated: false,
                        schema: String::schema_ref(),
                    }, MetaHeader {
                        name: "content-type".to_string(),
                        description: Some(CONTENT_TYPE_DESCRIPTION.to_string()),
                        required: false,
                        deprecated: false,
                        schema: String::schema_ref(),
                    }],
                },
                MetaResponse {
                    description: "Not modified",
                    status: Some(304),
                    content: vec![],
                    headers: vec![],
                },
                MetaResponse {
                    description: "Bad request",
                    status: Some(400),
                    content: vec![],
                    headers: vec![],
                },
                MetaResponse {
                    description: "Resource was not found",
                    status: Some(404),
                    content: vec![],
                    headers: vec![],
                },
                MetaResponse {
                    description: "Precondition failed",
                    status: Some(412),
                    content: vec![],
                    headers: vec![],
                },
                MetaResponse {
                    description: "The Content-Range response HTTP header indicates where in a full body message a partial message belongs.",
                    status: Some(416),
                    content: vec![],
                    headers: vec![],
                }, MetaResponse {
                    description: "Internal server error",
                    status: Some(500),
                    content: vec![],
                    headers: vec![],
                },
            ],
        }
    }

    fn register(_registry: &mut Registry) {}
}