cookie_monster/cookie/
same_site.rs

1use std::fmt::{self, Write};
2
3use crate::Cookie;
4
5/// The SameSite attribute.
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7pub enum SameSite {
8    Strict,
9    Lax,
10    None,
11}
12
13impl Cookie {
14    pub(crate) fn serialize_same_site(&self, buf: &mut String) {
15        let Some(same_site) = self.same_site else {
16            return;
17        };
18
19        let _ = write!(buf, "; SameSite={same_site}");
20    }
21}
22
23impl fmt::Display for SameSite {
24    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
25        match *self {
26            SameSite::Strict => write!(f, "Strict"),
27            SameSite::Lax => write!(f, "Lax"),
28            SameSite::None => write!(f, "None"),
29        }
30    }
31}