aboutsummaryrefslogtreecommitdiffstats
path: root/license-generator/src/main.rs
diff options
context:
space:
mode:
authorTeddy Wing2018-11-11 02:32:46 +0100
committerTeddy Wing2018-11-11 02:32:46 +0100
commit452c17a271258324ab7f84fb880c12f2e0d8472f (patch)
tree956652a8362605dcfdff1340c0b7283cb5db5822 /license-generator/src/main.rs
parentedf6fceedd9b4169ceb63172c60733ef84d78951 (diff)
downloaddome-key-web-452c17a271258324ab7f84fb880c12f2e0d8472f.tar.bz2
Extract 403 and 405 errors to functions
Like what I did in edf6fceedd9b4169ceb63172c60733ef84d78951 for 500 errors, extract these errors to functions also. Doesn't give us any gains in terms of reusability like it did before, as we're only responding with each of these errors once, but it does clean up the code in the `main()` function a bit.
Diffstat (limited to 'license-generator/src/main.rs')
-rw-r--r--license-generator/src/main.rs18
1 files changed, 5 insertions, 13 deletions
diff --git a/license-generator/src/main.rs b/license-generator/src/main.rs
index f2beb26..296db0a 100644
--- a/license-generator/src/main.rs
+++ b/license-generator/src/main.rs
@@ -76,14 +76,7 @@ fn main() -> Result<()> {
match req.param("REQUEST_METHOD") {
Some(method) => {
if method != "POST" {
- response::set_405(&mut req.stdout(), "POST")
- .unwrap_or(());
- write!(&mut req.stdout(), "Content-Type: text/plain
-
-405 Method Not Allowed")
- .unwrap_or(());
-
- return;
+ return response::error_405(&mut req.stdout(), "POST");
}
},
None => {
@@ -139,11 +132,10 @@ fn main() -> Result<()> {
);
}
- response::set_403(&mut req.stdout()).unwrap_or(());
- write!(&mut req.stdout(), "Content-Type: text/plain
-
-403 Forbidden: Invalid request signature")
- .unwrap_or(());
+ response::error_403(
+ &mut req.stdout(),
+ Some("Invalid request signature")
+ );
});
Ok(())