diff options
| author | Fuwn <[email protected]> | 2022-03-26 09:29:51 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2022-03-26 09:29:51 +0000 |
| commit | b965273e4032db2241ec13fc074a94556b205197 (patch) | |
| tree | 980947f4ae0825f5f535d5fdc4a251c4d0246fa9 | |
| parent | refactor(handle): simply further (diff) | |
| download | windmark-b965273e4032db2241ec13fc074a94556b205197.tar.xz windmark-b965273e4032db2241ec13fc074a94556b205197.zip | |
feat(response): temporary failure response
| -rw-r--r-- | examples/windmark.rs | 3 | ||||
| -rw-r--r-- | src/lib.rs | 4 | ||||
| -rw-r--r-- | src/response.rs | 6 |
3 files changed, 11 insertions, 2 deletions
diff --git a/examples/windmark.rs b/examples/windmark.rs index d719993..391b13e 100644 --- a/examples/windmark.rs +++ b/examples/windmark.rs @@ -60,6 +60,9 @@ fn main() -> std::io::Result<()> { .mount("/test", |_, _, _| { Response::Success("hi there\n=> / back".to_string()) }) + .mount("/temporary-failure", |_, _, _| { + Response::TemporaryFailure("Woops, temporarily...".into()) + }) .mount("/time", |_, _, _| { Response::Success( std::time::UNIX_EPOCH @@ -367,11 +367,11 @@ impl Router { "{}{}\r\n{}", response_status, match response_status { - 50 | 51 => &*content, + 40 | 50 | 51 => &*content, _ => " text/gemini; charset=utf-8", }, match response_status { - 50 | 51 => "".to_string(), + 40 | 50 | 51 => "".to_string(), _ => format!("{}{}{}", header, content, footer), } ) diff --git a/src/response.rs b/src/response.rs index 0a4b79e..961cf79 100644 --- a/src/response.rs +++ b/src/response.rs @@ -29,6 +29,7 @@ impl ToString for Header { pub enum Response { Success(String), NotFound(String), + TemporaryFailure(String), PermanentFailure(String), } @@ -42,6 +43,11 @@ pub(crate) fn to_value_set_status( value } + Response::TemporaryFailure(value) => { + *status = 40; + + value + } Response::NotFound(value) => { *status = 51; |