make shortlinks case insensitive
This commit is contained in:
23
readme.md
23
readme.md
@@ -33,6 +33,27 @@ a _really_ simple url shortener: less than 200 lines of Rust and one dependency
|
|||||||
|
|
||||||
a working [dockerfile](./Dockerfile) and [compose file](./compose.yaml) are provided.
|
a working [dockerfile](./Dockerfile) and [compose file](./compose.yaml) are provided.
|
||||||
|
|
||||||
|
## a note on case insensitivity
|
||||||
|
|
||||||
|
all shortlinks are case insenitive,
|
||||||
|
due to the lack of [urlencoding/decoding](#a-note-on-urlencoded-characters).
|
||||||
|
|
||||||
|
## a note on urlencoded characters
|
||||||
|
|
||||||
|
this program does not decode urlencoded strings before checking if strings match.
|
||||||
|
this is a deliberate choice to keep things as simple as possible.
|
||||||
|
|
||||||
|
avoid using links that may be encoded.
|
||||||
|
|
||||||
|
for links that will necessarily get encoded (still discouraged) (such as emojis),
|
||||||
|
put the urlencoded string.
|
||||||
|
for example, for the link <http://pls.cx/🤬> the following line is in my urls.txt:
|
||||||
|
|
||||||
|
```
|
||||||
|
/🤬 https://en.wikipedia.org/wiki/Controversies_of_Nestl%C3%A9 you may want the non-encoded version in case a client does not encode it? idk
|
||||||
|
/%f0%9f%a4%ac https://en.wikipedia.org/wiki/Controversies_of_Nestl%C3%A9
|
||||||
|
```
|
||||||
|
|
||||||
## why?
|
## why?
|
||||||
|
|
||||||
all url shorteners i've come across are too complicated:
|
all url shorteners i've come across are too complicated:
|
||||||
@@ -47,7 +68,7 @@ updating it.
|
|||||||
|
|
||||||
good question.
|
good question.
|
||||||
i'm not sure, but i think i want to separate my concerns?
|
i'm not sure, but i think i want to separate my concerns?
|
||||||
you might just want to configure your reverse proxy instead.
|
you might just want to configure your reverse proxy instead:
|
||||||
|
|
||||||
#### caddy
|
#### caddy
|
||||||
|
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ async fn process_socket(mut socket: BufStream<TcpStream>, urlmap: Arc<HashMap<St
|
|||||||
simple_response(socket, ResponseCode::BadRequest).await;
|
simple_response(socket, ResponseCode::BadRequest).await;
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
let path = path.to_lowercase();
|
||||||
|
|
||||||
if http_method != "GET" {
|
if http_method != "GET" {
|
||||||
println!("process_request: forbidden method");
|
println!("process_request: forbidden method");
|
||||||
@@ -53,7 +54,7 @@ async fn process_socket(mut socket: BufStream<TcpStream>, urlmap: Arc<HashMap<St
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let Some(location) = urlmap.get(path) else {
|
let Some(location) = urlmap.get(&path) else {
|
||||||
println!("process_request: not found");
|
println!("process_request: not found");
|
||||||
simple_response(socket, ResponseCode::NotFound).await;
|
simple_response(socket, ResponseCode::NotFound).await;
|
||||||
return;
|
return;
|
||||||
@@ -114,7 +115,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
Err(format!("Unable to parse line: '{}'", url_pair))?
|
Err(format!("Unable to parse line: '{}'", url_pair))?
|
||||||
};
|
};
|
||||||
|
|
||||||
urlmap.insert(slug.to_string(), redirect.to_string());
|
urlmap.insert(slug.to_lowercase(), redirect.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
let urlmap = Arc::new(urlmap);
|
let urlmap = Arc::new(urlmap);
|
||||||
|
|||||||
Reference in New Issue
Block a user