Skip to content

Commit

Permalink
🩹 Fix 401 causing web browsers to download 0 byte data
Browse files Browse the repository at this point in the history
  • Loading branch information
RemiBardon committed Mar 19, 2024
1 parent 7499b74 commit cb8b182
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/orangutan-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn rocket() -> _ {
update_content_github,
update_content_other,
])
.register("/", catchers![not_found])
.register("/", catchers![unauthorized, not_found])
.manage(ObjectReader::new())
.attach(AdHoc::on_liftoff("Tracing subsciber", |_| {
Box::pin(async move {
Expand Down Expand Up @@ -307,8 +307,7 @@ fn update_content_other(source: &str) -> BadRequest<String> {
BadRequest(format!("Source '{source}' is not supported."))
}

#[catch(404)]
async fn not_found() -> Result<NamedFile, &'static str> {
async fn _not_found() -> Result<NamedFile, &'static str> {
let website_id = WebsiteId::default();
let website_dir = match generate_website_if_needed(&website_id) {
Ok(dir) => dir,
Expand All @@ -328,6 +327,16 @@ async fn not_found() -> Result<NamedFile, &'static str> {
})
}

#[catch(401)]
async fn unauthorized() -> Result<NamedFile, &'static str> {
_not_found().await
}

#[catch(404)]
async fn not_found() -> Result<NamedFile, &'static str> {
_not_found().await
}

fn allowed_profiles<'r>(path: &String) -> Option<Vec<String>> {
let path = path.rsplit_once("@").unwrap_or((path, "")).0;
let data_file = data_file(&Path::new(path).to_path_buf());
Expand Down

0 comments on commit cb8b182

Please sign in to comment.