mirror of
https://github.com/samsonjs/agate.git
synced 2026-03-31 10:05:48 +00:00
Path validation
This commit is contained in:
parent
0e6163dcd9
commit
7eeba3959e
1 changed files with 10 additions and 4 deletions
14
src/main.rs
14
src/main.rs
|
|
@ -5,14 +5,12 @@ use {
|
|||
task,
|
||||
},
|
||||
async_tls::TlsAcceptor,
|
||||
rustls::{
|
||||
internal::pemfile::{certs, rsa_private_keys},
|
||||
},
|
||||
rustls::internal::pemfile::{certs, rsa_private_keys},
|
||||
std::{
|
||||
error::Error,
|
||||
fs::File,
|
||||
io::BufReader,
|
||||
path::Path,
|
||||
path::{Path, PathBuf},
|
||||
sync::Arc,
|
||||
},
|
||||
url::Url,
|
||||
|
|
@ -59,6 +57,14 @@ async fn connection(acceptor: TlsAcceptor, stream: TcpStream) -> Result {
|
|||
let url = Url::parse(request.trim())?;
|
||||
eprintln!("Got request: {:?}", url);
|
||||
|
||||
let path: PathBuf = url.path_segments().unwrap().collect();
|
||||
eprintln!("Path: {:?}", path);
|
||||
let path = Path::new(".").join(path).canonicalize()?;
|
||||
eprintln!("Path: {:?}", path);
|
||||
|
||||
// TODO: Return a not found error
|
||||
assert!(path.starts_with(std::env::current_dir()?));
|
||||
|
||||
let mut stream = stream.into_inner();
|
||||
stream.write_all(b"20 text/gemini\r\n").await?;
|
||||
stream.write_all(b"=> ").await?;
|
||||
|
|
|
|||
Loading…
Reference in a new issue