diff options
| author | Fuwn <[email protected]> | 2022-07-09 01:41:19 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2022-07-09 01:41:19 +0000 |
| commit | 4ae6f12bb59148f27f88fac30f5935133102c5f9 (patch) | |
| tree | 9d984c80f8f0de526523a320d562f8c3c94748e6 /src | |
| parent | chore(cargo): republish with --all-features (diff) | |
| download | windmark-4ae6f12bb59148f27f88fac30f5935133102c5f9.tar.xz windmark-4ae6f12bb59148f27f88fac30f5935133102c5f9.zip | |
feat(response): success with mime response
Diffstat (limited to 'src')
| -rw-r--r-- | src/response.rs | 9 | ||||
| -rw-r--r-- | src/router.rs | 10 |
2 files changed, 16 insertions, 3 deletions
diff --git a/src/response.rs b/src/response.rs index ed320b5..806eebb 100644 --- a/src/response.rs +++ b/src/response.rs @@ -23,6 +23,9 @@ pub enum Response<'a> { Input(String), SensitiveInput(String), Success(String), + /// A successful response where the MIME type of the response is manually + /// specific by the user + SuccessWithMime(String, String), #[cfg(feature = "auto-deduce-mime")] /// A successful response where the MIME type of the response is /// automatically deduced from the provided bytes @@ -66,6 +69,12 @@ pub(crate) fn to_value_set_status( value } + Response::SuccessWithMime(value, value_mime) => { + *status = 23; + *mime = value_mime; + + value + } Response::SuccessFile(value, value_mime) => { *status = 21; // Internal status code, not real. *mime = value_mime; diff --git a/src/router.rs b/src/router.rs index 10a8f92..d4663f7 100644 --- a/src/router.rs +++ b/src/router.rs @@ -384,7 +384,10 @@ impl Router { .write_all( format!( "{}{}\r\n{}", - if response_status == 21 || response_status == 22 { + if response_status == 21 + || response_status == 22 + || response_status == 23 + { 20 } else { response_status @@ -395,14 +398,15 @@ impl Router { " text/gemini; charset={}; lang={}", self.charset, self.language ), + 21 => response_mime_type, #[cfg(feature = "auto-deduce-mime")] 22 => format!(" {}", tree_magic::from_u8(&*content.as_bytes())), - 21 => response_mime_type, + 23 => response_mime_type, _ => format!(" {}", content), }, match response_status { 20 => format!("{}{}\n{}", header, content, footer), - 21 | 22 => content.to_string(), + 21 | 22 | 23 => content.to_string(), _ => "".to_string(), } ) |