Flip match_prefix args
parent
2b93aa8b83
commit
f81d819c31
|
@ -13,10 +13,13 @@ pub mod prelude;
|
||||||
pub mod relay;
|
pub mod relay;
|
||||||
pub mod server;
|
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) {
|
if hay.starts_with (prefix) {
|
||||||
Some (&hay [needle.len ()..])
|
Some (&hay [prefix.len ()..])
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
None
|
None
|
||||||
|
|
|
@ -467,7 +467,7 @@ async fn handle_all (req: Request <Body>, state: Arc <RelayState>)
|
||||||
// This is stuff the server can use. Clients can't
|
// This is stuff the server can use. Clients can't
|
||||||
// POST right now
|
// 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 ();
|
let request_code = request_code.into ();
|
||||||
handle_http_response (req, state, request_code).await
|
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 {
|
let api_key = match api_key {
|
||||||
None => return Ok (error_reply (StatusCode::UNAUTHORIZED, "Can't register as server without an API key")),
|
None => return Ok (error_reply (StatusCode::UNAUTHORIZED, "Can't register as server without an API key")),
|
||||||
Some (x) => x,
|
Some (x) => x,
|
||||||
};
|
};
|
||||||
handle_http_listen (state, listen_code.into (), api_key.as_bytes ()).await
|
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 == "" {
|
if rest == "" {
|
||||||
#[derive (Serialize)]
|
#[derive (Serialize)]
|
||||||
struct ServerEntry <'a> {
|
struct ServerEntry <'a> {
|
||||||
|
|
|
@ -442,7 +442,7 @@ async fn internal_serve_all (
|
||||||
return Favicon;
|
return Favicon;
|
||||||
}
|
}
|
||||||
|
|
||||||
let uri = match prefix_match (uri, "/files") {
|
let uri = match prefix_match ("/files", uri) {
|
||||||
Some (x) => x,
|
Some (x) => x,
|
||||||
None => return Root,
|
None => return Root,
|
||||||
};
|
};
|
||||||
|
|
1
todo.md
1
todo.md
|
@ -1,7 +1,6 @@
|
||||||
- Not working behind Nginx (Works okay behind Caddy)
|
- Not working behind Nginx (Works okay behind Caddy)
|
||||||
- Reduce idle memory use?
|
- Reduce idle memory use?
|
||||||
|
|
||||||
- Flip match_prefix args
|
|
||||||
- Impl multi-range / multi-part byte serving
|
- Impl multi-range / multi-part byte serving
|
||||||
- Allow spaces in server names
|
- Allow spaces in server names
|
||||||
- Deny unused HTTP methods for endpoints
|
- Deny unused HTTP methods for endpoints
|
||||||
|
|
Loading…
Reference in New Issue