poem_openapi/response/
static_file.rs

1use poem::{Body, web::StaticFileResponse};
2
3use crate::{
4    ApiResponse,
5    payload::{Binary, Payload},
6    registry::{MetaHeader, MetaMediaType, MetaResponse, MetaResponses, Registry},
7    types::Type,
8};
9
10const 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")."#;
11const 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."#;
12const 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)."#;
13
14impl ApiResponse for StaticFileResponse {
15    fn meta() -> MetaResponses {
16        MetaResponses {
17            responses: vec![
18                MetaResponse {
19                    description: "",
20                    status: Some(200),
21                    status_range: None,
22                    content: vec![MetaMediaType {
23                        content_type: Binary::<Body>::CONTENT_TYPE,
24                        schema: Binary::<Body>::schema_ref(),
25                    }],
26                    headers: vec![
27                        MetaHeader {
28                            name: "etag".to_string(),
29                            description: Some(ETAG_DESCRIPTION.to_string()),
30                            required: false,
31                            deprecated: false,
32                            schema: String::schema_ref(),
33                        },
34                        MetaHeader {
35                            name: "last-modified".to_string(),
36                            description: Some(LAST_MODIFIED_DESCRIPTION.to_string()),
37                            required: false,
38                            deprecated: false,
39                            schema: String::schema_ref(),
40                        },
41                        MetaHeader {
42                            name: "content-type".to_string(),
43                            description: Some(CONTENT_TYPE_DESCRIPTION.to_string()),
44                            required: false,
45                            deprecated: false,
46                            schema: String::schema_ref(),
47                        },
48                    ],
49                },
50                MetaResponse {
51                    description: "Not modified",
52                    status: Some(304),
53                    status_range: None,
54                    content: vec![],
55                    headers: vec![],
56                },
57                MetaResponse {
58                    description: "Bad request",
59                    status: Some(400),
60                    status_range: None,
61                    content: vec![],
62                    headers: vec![],
63                },
64                MetaResponse {
65                    description: "Resource was not found",
66                    status: Some(404),
67                    status_range: None,
68                    content: vec![],
69                    headers: vec![],
70                },
71                MetaResponse {
72                    description: "Precondition failed",
73                    status: Some(412),
74                    status_range: None,
75                    content: vec![],
76                    headers: vec![],
77                },
78                MetaResponse {
79                    description: "The Content-Range response HTTP header indicates where in a full body message a partial message belongs.",
80                    status: Some(416),
81                    status_range: None,
82                    content: vec![],
83                    headers: vec![],
84                },
85                MetaResponse {
86                    description: "Internal server error",
87                    status: Some(500),
88                    status_range: None,
89                    content: vec![],
90                    headers: vec![],
91                },
92            ],
93        }
94    }
95
96    fn register(_registry: &mut Registry) {}
97}