-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tower)!: predicates refactoring
- Loading branch information
1 parent
5f547b9
commit 5d94f26
Showing
18 changed files
with
352 additions
and
341 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,58 @@ | ||
use std::{ | ||
marker::PhantomData, | ||
sync::{atomic::AtomicPtr, Arc, RwLock}, | ||
}; | ||
|
||
use async_trait::async_trait; | ||
use hitbox_backend::predicates::{Predicate, PredicateResult}; | ||
|
||
use crate::CacheableHttpRequest; | ||
use crate::{CacheableHttpRequest, CacheableHttpResponse}; | ||
|
||
pub mod body; | ||
pub mod header; | ||
pub mod path; | ||
pub mod query; | ||
|
||
pub struct NeutralPredicate; | ||
pub struct NeutralPredicate<ReqBody> { | ||
_req: PhantomData<AtomicPtr<Box<ReqBody>>>, // FIX: NOT HEHE | ||
} | ||
|
||
impl NeutralPredicate { | ||
impl<ReqBody> NeutralPredicate<ReqBody> { | ||
pub fn new() -> Self { | ||
NeutralPredicate | ||
NeutralPredicate { _req: PhantomData } | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl<ReqBody> Predicate<CacheableHttpRequest<ReqBody>> for NeutralPredicate | ||
impl<ReqBody> Predicate for NeutralPredicate<ReqBody> | ||
where | ||
ReqBody: Send + 'static, | ||
{ | ||
async fn check( | ||
&self, | ||
subject: CacheableHttpRequest<ReqBody>, | ||
) -> PredicateResult<CacheableHttpRequest<ReqBody>> { | ||
type Subject = CacheableHttpRequest<ReqBody>; | ||
|
||
async fn check(&self, subject: Self::Subject) -> PredicateResult<Self::Subject> { | ||
PredicateResult::Cacheable(subject) | ||
} | ||
} | ||
|
||
pub struct NeutralResponsePredicate<ResBody> { | ||
_res: PhantomData<fn() -> ResBody>, // FIX: HEHE | ||
} | ||
|
||
impl<ResBody> NeutralResponsePredicate<ResBody> { | ||
pub fn new() -> Self { | ||
NeutralResponsePredicate { _res: PhantomData } | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl<ResBody> Predicate for NeutralResponsePredicate<ResBody> | ||
where | ||
ResBody: Send + 'static, | ||
{ | ||
type Subject = CacheableHttpResponse<ResBody>; | ||
|
||
async fn check(&self, subject: Self::Subject) -> PredicateResult<Self::Subject> { | ||
PredicateResult::Cacheable(subject) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.