an http based roguelike rpg about jelqing
| 1 | #[derive(Clone, Copy)] |
| 2 | pub enum Scheme { |
| 3 | Basic, |
| 4 | Bearer, |
| 5 | Excuse, |
| 6 | Ruler, |
| 7 | } |
| 8 | |
| 9 | impl Scheme { |
| 10 | fn name(self) -> &'static str { |
| 11 | match self { |
| 12 | Self::Basic => "basic", |
| 13 | Self::Bearer => "bearer", |
| 14 | Self::Excuse => "excuse", |
| 15 | Self::Ruler => "ruler", |
| 16 | } |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | pub fn parse_credentials(authorization: &str, scheme: Scheme) -> Option<&str> { |
| 21 | let (given, rest) = authorization.trim().split_once(' ')?; |
| 22 | given |
| 23 | .eq_ignore_ascii_case(scheme.name()) |
| 24 | .then(|| rest.trim().trim_matches('"')) |
| 25 | } |
| 26 | |
| 27 | pub fn etag_matches(condition: &str, etag: &str) -> bool { |
| 28 | condition |
| 29 | .split(',') |
| 30 | .map(str::trim) |
| 31 | .any(|tag| tag == "*" || tag.trim_start_matches("W/") == etag) |
| 32 | } |