summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpennae <github@quasiparticle.net>2024-08-17 01:23:36 +0200
committerpennae <github@quasiparticle.net>2024-08-17 01:23:36 +0200
commit22711c21d0213ae78132c28b56be98f9d53af456 (patch)
treed4038d44a3c372f806444a556d97b3658efb1338 /src
parent231b3fcc43fec88c204cc3b8c5a29c2437690f01 (diff)
downloadminor-skulk-22711c21d0213ae78132c28b56be98f9d53af456.tar.gz
minor-skulk-22711c21d0213ae78132c28b56be98f9d53af456.tar.xz
minor-skulk-22711c21d0213ae78132c28b56be98f9d53af456.zip
update for depsHEADmain
Diffstat (limited to 'src')
-rw-r--r--src/auth.rs22
-rw-r--r--src/cache.rs4
-rw-r--r--src/utils.rs8
3 files changed, 17 insertions, 17 deletions
diff --git a/src/auth.rs b/src/auth.rs
index 304ab0f..57d481d 100644
--- a/src/auth.rs
+++ b/src/auth.rs
@@ -76,21 +76,21 @@ impl<T, Src: AuthSource> Authenticated<T, Src> {
async fn parse_auth<'a>(
request: &'a Request<'_>,
- ) -> Outcome<AuthKind<'a>, (Status, anyhow::Error), ()> {
+ ) -> Outcome<AuthKind<'a>, (Status, anyhow::Error), Status> {
let auth = match request.headers().get("authorization").take(2).enumerate().last() {
Some((0, h)) => h,
Some((_, _)) => {
- return Outcome::Failure((
+ return Outcome::Error((
Status::BadRequest,
anyhow!("multiple authorization headers present"),
))
},
- None => return Outcome::Forward(()),
+ None => return Outcome::Forward(Status::Unauthorized),
};
if let Some(hawk) = drop_auth_prefix(auth, "hawk ") {
match Header::from_str(hawk) {
Ok(header) => Outcome::Success(AuthKind::Hawk { header }),
- Err(e) => Outcome::Failure((
+ Err(e) => Outcome::Error((
Status::Unauthorized,
anyhow!(e).context("malformed hawk header"),
)),
@@ -98,14 +98,14 @@ impl<T, Src: AuthSource> Authenticated<T, Src> {
} else if let Some(token) = drop_auth_prefix(auth, "bearer ") {
Outcome::Success(AuthKind::Token { token })
} else {
- Outcome::Forward(())
+ Outcome::Forward(Status::Unauthorized)
}
}
pub async fn get_conn<'r>(req: &'r Request<'_>) -> Result<&'r DbConn> {
match <&'r DbConn as FromRequest<'r>>::from_request(req).await {
Outcome::Success(db) => Ok(db),
- Outcome::Failure((_, e)) => Err(e.context("get db connection")),
+ Outcome::Error((_, e)) => Err(e.context("get db connection")),
_ => Err(anyhow!("could not get db connection")),
}
}
@@ -168,7 +168,7 @@ impl<'r, Src: AuthSource> FromRequest<'r> for Authenticated<(), Src> {
},
Err(e) => {
request.local_cache(|| Some(InvalidTokenUsed));
- Outcome::Failure((Status::Unauthorized, anyhow!(e)))
+ Outcome::Error((Status::Unauthorized, anyhow!(e)))
},
}
}
@@ -185,12 +185,12 @@ impl<'r, T: Deserialize<'r>, Src: AuthSource> FromData<'r> for Authenticated<T,
let raw_json = match data.open(limit).into_string().await {
Ok(r) if r.is_complete() => local_cache!(request, r.into_inner()),
Ok(_) => {
- return data::Outcome::Failure((
+ return data::Outcome::Error((
Status::PayloadTooLarge,
anyhow!("request too large"),
))
},
- Err(e) => return data::Outcome::Failure((Status::InternalServerError, e.into())),
+ Err(e) => return data::Outcome::Error((Status::InternalServerError, e.into())),
};
let verify_result = match auth {
AuthKind::Hawk { header } => Self::verify_hawk(request, header, Some(raw_json)).await,
@@ -202,7 +202,7 @@ impl<'r, T: Deserialize<'r>, Src: AuthSource> FromData<'r> for Authenticated<T,
},
Err(e) => {
request.local_cache(|| Some(InvalidTokenUsed));
- return Outcome::Failure((Status::Unauthorized, anyhow!(e)));
+ return Outcome::Error((Status::Unauthorized, anyhow!(e)));
},
};
match result {
@@ -213,7 +213,7 @@ impl<'r, T: Deserialize<'r>, Src: AuthSource> FromData<'r> for Authenticated<T,
Category::Data => Status::UnprocessableEntity,
_ => Status::BadRequest,
};
- Outcome::Failure((status, anyhow!(e)))
+ Outcome::Error((status, anyhow!(e)))
},
}
}
diff --git a/src/cache.rs b/src/cache.rs
index 680d9da..3319835 100644
--- a/src/cache.rs
+++ b/src/cache.rs
@@ -1,7 +1,7 @@
use std::borrow::Cow;
use rocket::{
- http::Header,
+ http::{Header, Status},
request::{self, FromRequest},
response::{self, Responder},
Request,
@@ -36,7 +36,7 @@ impl<'r> FromRequest<'r> for IfNoneMatch<'r> {
async fn from_request(req: &'r Request<'_>) -> request::Outcome<Self, Self::Error> {
match req.headers().get_one("if-none-match") {
Some(h) => request::Outcome::Success(Self(h)),
- None => request::Outcome::Forward(()),
+ None => request::Outcome::Forward(Status::Ok),
}
}
}
diff --git a/src/utils.rs b/src/utils.rs
index 70c8c11..dc08bc0 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -19,11 +19,11 @@ macro_rules! try_outcome_data {
($data:expr, $e:expr) => {
match $e {
::rocket::outcome::Outcome::Success(val) => val,
- ::rocket::outcome::Outcome::Failure(e) => {
- return ::rocket::outcome::Outcome::Failure(::std::convert::From::from(e))
+ ::rocket::outcome::Outcome::Error(e) => {
+ return ::rocket::outcome::Outcome::Error(::std::convert::From::from(e))
},
- ::rocket::outcome::Outcome::Forward(()) => {
- return ::rocket::outcome::Outcome::Forward($data)
+ ::rocket::outcome::Outcome::Forward(e) => {
+ return ::rocket::outcome::Outcome::Forward(($data, e))
},
}
};