Skip to content

Commit 493fdbd

Browse files
committed
Cosmetic fixes, fix content disposition filename
Few debug cosmetic updates and remove path from content-disposition header, only filename should remain. Signed-off-by: Denys Fedoryshchenko <denys.f@collabora.com>
1 parent 4afe47d commit 493fdbd

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

src/main.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use headers::HeaderMap;
2727
use std::{net::SocketAddr, path::PathBuf};
2828
use tokio::io::AsyncSeekExt;
2929
use tokio_util::io::ReaderStream;
30+
use std::path;
3031

3132
#[derive(Parser, Debug)]
3233
#[command(version, about, long_about = None)]
@@ -104,11 +105,11 @@ async fn initial_setup() -> Option<RustlsConfig> {
104105
.await;
105106
match config {
106107
Ok(tlsconf) => {
107-
println!("TLS config loaded");
108+
println!("TLS config loaded, HTTPS mode enabled");
108109
Some(tlsconf)
109110
}
110111
Err(e) => {
111-
eprintln!("Error reading TLS config: {:?}", e);
112+
eprintln!("TLS config error: {:?}, switching to plain HTTP", e);
112113
None
113114
}
114115
}
@@ -176,6 +177,7 @@ async fn ax_post_file(headers: HeaderMap, mut multipart: Multipart) -> (StatusCo
176177
let message = verify_auth_hdr(&headers);
177178
// return status and message
178179
if message != "" {
180+
println!("Unauthorized POST request");
179181
return (StatusCode::UNAUTHORIZED, Vec::new());
180182
}
181183
println!("Authorized");
@@ -247,6 +249,15 @@ async fn ax_post_file(headers: HeaderMap, mut multipart: Multipart) -> (StatusCo
247249
(StatusCode::OK, Vec::new())
248250
}
249251

252+
fn filename_from_fullpath(filepath: &str) -> String {
253+
let path = path::Path::new(filepath);
254+
let filename = path.file_name();
255+
match filename {
256+
Some(filename) => return filename.to_str().unwrap().to_string(),
257+
None => return filepath.to_string(),
258+
}
259+
}
260+
250261
/*
251262
Retrieve file in the server from the cache/storage and return it to the client
252263
@@ -274,12 +285,12 @@ async fn ax_get_file(
274285
header::CONTENT_TYPE,
275286
"application/octet-stream".parse().unwrap(),
276287
);
288+
let filename_only = filename_from_fullpath(&original_filename);
277289
headers.insert(
278290
header::CONTENT_DISPOSITION,
279-
format!("attachment; filename=\"{}\"", &original_filename)
280-
.parse()
281-
.unwrap(),
291+
format!("attachment; filename=\"{}\"", filename_only).parse().unwrap(),
282292
);
293+
283294
headers.insert(header::ACCEPT_RANGES, "bytes".parse().unwrap());
284295

285296
/* Usually HEAD is used to check if the file exists and range is supported */

src/storjwt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn verify_jwt_token(token_str: &str) -> Result<BTreeMap<String, String>, jwt
1818
let token: Token<Header, BTreeMap<String, String>, _> = match verify_result {
1919
Ok(token) => token,
2020
Err(e) => {
21-
println!("verify_result Error: {:?}", e);
21+
println!("verify_result Error: {:?} token_str: {}", e, token_str);
2222
return Err(e);
2323
}
2424
};

0 commit comments

Comments
 (0)