wip: split garage_api into garage_api_{common,s3,k2v,admin}

This commit is contained in:
Alex Auvolat
2025-01-31 18:18:04 +01:00
parent 9330fd79d3
commit 9fa20d45be
52 changed files with 605 additions and 191 deletions
+22
View File
@@ -0,0 +1,22 @@
//! Module containing various helpers for encoding
/// Encode &str for use in a URI
pub fn uri_encode(string: &str, encode_slash: bool) -> String {
let mut result = String::with_capacity(string.len() * 2);
for c in string.chars() {
match c {
'a'..='z' | 'A'..='Z' | '0'..='9' | '_' | '-' | '~' | '.' => result.push(c),
'/' if encode_slash => result.push_str("%2F"),
'/' if !encode_slash => result.push('/'),
_ => {
result.push_str(
&format!("{}", c)
.bytes()
.map(|b| format!("%{:02X}", b))
.collect::<String>(),
);
}
}
}
result
}