Flip match_prefix args

main
_ 2020-11-08 23:53:31 +00:00
parent 2b93aa8b83
commit f81d819c31
4 changed files with 10 additions and 8 deletions

View File

@ -13,10 +13,13 @@ pub mod prelude;
pub mod relay;
pub mod server;
pub fn prefix_match <'a> (hay: &'a str, needle: &str) -> Option <&'a str>
// The arguments are in order so they are in order overall:
// e.g. prefix_match ("/prefix", "/prefix/middle/suffix") -> "/middle/suffix"
pub fn prefix_match <'a> (prefix: &str, hay: &'a str) -> Option <&'a str>
{
if hay.starts_with (needle) {
Some (&hay [needle.len ()..])
if hay.starts_with (prefix) {
Some (&hay [prefix.len ()..])
}
else {
None

View File

@ -467,7 +467,7 @@ async fn handle_all (req: Request <Body>, state: Arc <RelayState>)
// This is stuff the server can use. Clients can't
// POST right now
return Ok (if let Some (request_code) = prefix_match (path, "/7ZSFUKGV/http_response/") {
return Ok (if let Some (request_code) = prefix_match ("/7ZSFUKGV/http_response/", path) {
let request_code = request_code.into ();
handle_http_response (req, state, request_code).await
}
@ -476,14 +476,14 @@ async fn handle_all (req: Request <Body>, state: Arc <RelayState>)
});
}
Ok (if let Some (listen_code) = prefix_match (path, "/7ZSFUKGV/http_listen/") {
Ok (if let Some (listen_code) = prefix_match ("/7ZSFUKGV/http_listen/", path) {
let api_key = match api_key {
None => return Ok (error_reply (StatusCode::UNAUTHORIZED, "Can't register as server without an API key")),
Some (x) => x,
};
handle_http_listen (state, listen_code.into (), api_key.as_bytes ()).await
}
else if let Some (rest) = prefix_match (path, "/frontend/servers/") {
else if let Some (rest) = prefix_match ("/frontend/servers/", path) {
if rest == "" {
#[derive (Serialize)]
struct ServerEntry <'a> {

View File

@ -442,7 +442,7 @@ async fn internal_serve_all (
return Favicon;
}
let uri = match prefix_match (uri, "/files") {
let uri = match prefix_match ("/files", uri) {
Some (x) => x,
None => return Root,
};

View File

@ -1,7 +1,6 @@
- Not working behind Nginx (Works okay behind Caddy)
- Reduce idle memory use?
- Flip match_prefix args
- Impl multi-range / multi-part byte serving
- Allow spaces in server names
- Deny unused HTTP methods for endpoints