-
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.
- Loading branch information
1 parent
77a64bd
commit d897c95
Showing
7 changed files
with
85 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,36 @@ | ||
#[derive(Clone)] | ||
pub struct Config { | ||
pub query: (String, String), | ||
use hitbox_http::CacheableHttpRequest; | ||
use hitbox::predicates::Predicate; | ||
use hitbox_http::predicates::{NeutralPredicate, query::QueryPredicate}; | ||
|
||
pub enum RequestPredicate { | ||
Query { key: String, value: String }, | ||
} | ||
|
||
pub struct EndpointConfig { | ||
pub request_predicates: Vec<RequestPredicate>, | ||
} | ||
|
||
impl Config { | ||
pub fn new() -> Self { | ||
Self { query: (String::from("key"), String::from("value")) } | ||
impl EndpointConfig { | ||
pub fn create<ReqBody>(&self) -> Box<dyn Predicate<Subject = CacheableHttpRequest<ReqBody>>> | ||
where | ||
ReqBody: Send, | ||
{ | ||
let acc_predicate = Box::new(NeutralPredicate::new()); | ||
self | ||
.request_predicates | ||
.iter() | ||
.rfold(acc_predicate, |inner, predicate| match predicate { | ||
RequestPredicate::Query { key, value } => Box::new(inner.query(key, value)) | ||
//PredicateType::Header { key, value } => Box::new(inner.header(key, value)), | ||
//PredicateType::Body => Box::new(inner.body()), | ||
}) | ||
} | ||
} | ||
|
||
impl Default for EndpointConfig { | ||
fn default() -> Self { | ||
Self { | ||
request_predicates: Vec::new(), | ||
} | ||
} | ||
} |
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,7 +1,7 @@ | ||
pub mod config; | ||
pub mod dummy; | ||
pub mod future; | ||
pub mod layer; | ||
pub mod service; | ||
pub mod config; | ||
|
||
pub use layer::Cache; |
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