poem_openapi/response/
static_file.rs

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