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 cb8b182 commit 9c8d397
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/orangutan-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "orangutan-server"
version = "0.4.0"
version = "0.4.1"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
17 changes: 9 additions & 8 deletions src/orangutan-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ use rocket::http::uri::Origin;
use rocket::http::{Cookie, CookieJar, SameSite, Status};
use rocket::outcome::Outcome;
use rocket::request::FromRequest;
use rocket::response::status::{BadRequest, NotFound};
use rocket::response::status::BadRequest;
use rocket::response::Redirect;
use rocket::{catch, catchers, get, post, request, routes, Either, Request, Responder, State};
use rocket::{catch, catchers, get, post, request, routes, Request, Responder, State};
use time::Duration;
use tracing::{debug, error, trace, Level};
use tracing_subscriber::FmtSubscriber;
Expand Down Expand Up @@ -70,7 +70,8 @@ fn rocket() -> _ {
.attach(AdHoc::on_liftoff("Website generation", |rocket| {
Box::pin(async move {
if let Err(err) = liftoff() {
error!("Error: {}", err);
// We drop the error to get a Rocket-formatted panic.
drop(err);
rocket.shutdown().notify();
}
})
Expand Down Expand Up @@ -183,7 +184,7 @@ async fn handle_request(
origin: &Origin<'_>,
token: Option<Token>,
object_reader: &State<ObjectReader>,
) -> Result<Either<ReadObjectResponse, NotFound<()>>, object_reader::Error> {
) -> Result<Option<ReadObjectResponse>, object_reader::Error> {
let biscuit = token.map(|t| t.biscuit);

// FIXME: Handle error
Expand Down Expand Up @@ -222,7 +223,7 @@ async fn handle_request(
.map(|o| o.to_owned())
else {
error!("No file matching '{}' found in stored objects", &path);
return Ok(Either::Right(NotFound(())));
return Ok(None);
};

let allowed_profiles = allowed_profiles(&object_key);
Expand All @@ -233,7 +234,7 @@ async fn handle_request(
&path
);

return Ok(Either::Left(
return Ok(Some(
object_reader.read_object(&object_key, &website_id).await,
));
};
Expand Down Expand Up @@ -279,10 +280,10 @@ async fn handle_request(
}
if profile.is_none() {
debug!("No profile allowed in token");
return Ok(Either::Right(NotFound(())));
return Ok(None);
}

Ok(Either::Left(
Ok(Some(
object_reader.read_object(object_key, &website_id).await,
))
}
Expand Down

0 comments on commit 9c8d397

Please sign in to comment.