🐛 Allowing spaces in server names

main
_ 2020-11-09 00:04:35 +00:00
parent f81d819c31
commit 49cd292115
2 changed files with 11 additions and 6 deletions

View File

@ -108,7 +108,7 @@ struct Config {
impl From <&ConfigFile> for Config {
fn from (f: &ConfigFile) -> Self {
let trips = HashMap::from_iter (f.server_tripcodes.iter ()
let server_tripcodes = HashMap::from_iter (f.server_tripcodes.iter ()
.map (|(k, v)| {
use std::convert::TryInto;
let bytes: Vec <u8> = base64::decode (v).unwrap ();
@ -116,11 +116,15 @@ impl From <&ConfigFile> for Config {
let v = blake3::Hash::from (bytes);
(k.clone (), v)
let k = percent_encoding::percent_encode (k.as_bytes (), percent_encoding::NON_ALPHANUMERIC).to_string ();
debug! ("Tripcode {} => {}", k, v.to_hex ());
(k, v)
}));
Self {
server_tripcodes: trips,
server_tripcodes,
}
}
}
@ -485,10 +489,12 @@ async fn handle_all (req: Request <Body>, state: Arc <RelayState>)
}
else if let Some (rest) = prefix_match ("/frontend/servers/", path) {
if rest == "" {
use std::borrow::Cow;
#[derive (Serialize)]
struct ServerEntry <'a> {
path: &'a str,
name: &'a str,
name: Cow <'a, str>,
}
#[derive (Serialize)]
@ -503,7 +509,7 @@ async fn handle_all (req: Request <Body>, state: Arc <RelayState>)
let page = ServerListPage {
servers: names.iter ()
.map (|name| ServerEntry {
name: &name,
name: percent_encoding::percent_decode_str (name).decode_utf8 ().unwrap_or_else (|_| "Server name isn't UTF-8".into ()),
path: &name,
})
.collect (),

View File

@ -2,7 +2,6 @@
- Reduce idle memory use?
- Impl multi-range / multi-part byte serving
- Allow spaces in server names
- Deny unused HTTP methods for endpoints
- ETag cache based on mtime
- Server-side hash?