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