Skip to content

Commit

Permalink
add allow_anonymous to AsyncRequireAuthorizationLayer
Browse files Browse the repository at this point in the history
  • Loading branch information
calebbourg committed Nov 5, 2024
1 parent 50add1e commit 6a727df
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions rama-http/src/layer/auth/async_require_authorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,28 @@ use std::future::Future;
#[derive(Debug, Clone)]
pub struct AsyncRequireAuthorizationLayer<T> {
auth: T,
allow_anonymous: bool,
}

impl<T> AsyncRequireAuthorizationLayer<T> {
/// Authorize requests using a custom scheme.
pub const fn new(auth: T) -> AsyncRequireAuthorizationLayer<T> {
Self { auth }
Self {
auth: auth,
allow_anonymous: false,
}
}

/// Allow anonymous requests.
pub fn set_allow_anonymous(&mut self, allow_anonymous: bool) -> &mut Self {
self.allow_anonymous = allow_anonymous;
self
}

/// Allow anonymous requests.
pub fn with_allow_anonymous(mut self, allow_anonymous: bool) -> Self {
self.allow_anonymous = allow_anonymous;
self
}
}

Expand All @@ -159,14 +175,31 @@ where
pub struct AsyncRequireAuthorization<S, T> {
inner: S,
auth: T,
allow_anonymous: bool,
}

impl<S, T> AsyncRequireAuthorization<S, T> {
/// Authorize requests using a custom scheme.
///
/// The `Authorization` header is required to have the value provided.
pub const fn new(inner: S, auth: T) -> AsyncRequireAuthorization<S, T> {
Self { inner, auth }
Self {
inner: inner,
auth: auth,
allow_anonymous: false,
}
}

/// Allow anonymous requests.
pub fn set_allow_anonymous(&mut self, allow_anonymous: bool) -> &mut Self {
self.allow_anonymous = allow_anonymous;
self
}

/// Allow anonymous requests.
pub fn with_allow_anonymous(mut self, allow_anonymous: bool) -> Self {
self.allow_anonymous = allow_anonymous;
self
}

define_inner_service_accessors!();
Expand Down

0 comments on commit 6a727df

Please sign in to comment.