]> git.scottworley.com Git - voter/blobdiff - src/main.rs
Set-Cookie flags are ;-separated
[voter] / src / main.rs
index d15194fbb74d055370dc600ecd4604bc01798a57..f75557e95aa67f7bb9fc5fb98ebd8b8f67b743f6 100644 (file)
@@ -47,21 +47,22 @@ fn get_voter(request: &cgi::Request) -> Result<&[u8], cgi::Response> {
 
 fn tally_votes(dir: PathBuf) -> std::io::Result<HashMap<String, HashSet<String>>> {
     let mut tally: HashMap<String, HashSet<String>> = HashMap::new();
-    let vfile = std::fs::File::open(dir.join("votes"))?;
-    for liner in std::io::BufReader::new(vfile).lines() {
-        let line = liner?;
-        if let Some((voter, datum)) = line.split_once(' ') {
-            if voter.len() == COOKIE_LENGTH {
-                if let Some((vote, candidate)) = datum.split_once(' ') {
-                    if vote == "0" {
-                        if let Some(entry) = tally.get_mut(candidate) {
-                            entry.remove(voter);
+    if let Ok(vfile) = std::fs::File::open(dir.join("votes")) {
+        for liner in std::io::BufReader::new(vfile).lines() {
+            let line = liner?;
+            if let Some((voter, datum)) = line.split_once(' ') {
+                if voter.len() == COOKIE_LENGTH {
+                    if let Some((vote, candidate)) = datum.split_once(' ') {
+                        if vote == "0" {
+                            if let Some(entry) = tally.get_mut(candidate) {
+                                entry.remove(voter);
+                            }
+                        } else if vote == "1" {
+                            tally
+                                .entry(candidate.to_owned())
+                                .or_default()
+                                .insert(voter.to_owned());
                         }
-                    } else if vote == "1" {
-                        tally
-                            .entry(candidate.to_owned())
-                            .or_default()
-                            .insert(voter.to_owned());
                     }
                 }
             }
@@ -91,7 +92,7 @@ fn set_cookie(mut response: cgi::Response, path: &str) -> Result<cgi::Response,
                 COOKIE_NAME,
                 b"=",
                 &make_random_id(),
-                b"; Secure HttpOnly SameSite=Strict Max-Age=30000000 Path=",
+                b"; Secure; HttpOnly; SameSite=Strict; Max-Age=30000000; Path=",
                 path.as_bytes(),
             ]
             .concat(),