aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml2
-rw-r--r--README.md6
-rw-r--r--examples/windmark.rs6
-rw-r--r--src/response.rs9
-rw-r--r--src/router.rs10
5 files changed, 26 insertions, 7 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 11506e1..45158de 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -2,7 +2,7 @@
[package]
name = "windmark"
-version = "0.1.18"
+version = "0.1.19"
authors = ["Fuwn <[email protected]>"]
edition = "2021"
description = "An elegant and highly performant async Gemini server framework"
diff --git a/README.md b/README.md
index 414bd15..4f0290a 100644
--- a/README.md
+++ b/README.md
@@ -15,15 +15,15 @@ the modern age!
# Cargo.toml
[dependencies]
-windmark = "0.1.18"
+windmark = "0.1.19"
tokio = { version = "0.2.4", features = ["full"] }
# If you would like to use the built-in logger (recommended)
-# windmark = { version = "0.1.18", features = ["logger"] }
+# windmark = { version = "0.1.19", features = ["logger"] }
# If you would like to use the built-in MIME dedection when `Success`-ing a file
# (recommended)
-# windmark = { version = "0.1.18", features = ["auto-deduce-mime"] }
+# windmark = { version = "0.1.19", features = ["auto-deduce-mime"] }
```
### Implement a Windmark server
diff --git a/examples/windmark.rs b/examples/windmark.rs
index 80b0cba..736eb54 100644
--- a/examples/windmark.rs
+++ b/examples/windmark.rs
@@ -103,6 +103,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
}),
);
router.mount(
+ "/specific-mime",
+ Box::new(|_| {
+ Response::SuccessWithMime("hi".to_string(), "text/plain".to_string())
+ }),
+ );
+ router.mount(
"/ip",
Box::new(|context| {
Response::Success(
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(),
}
)