Skip to content

Commit

Permalink
feat(extractors): Fix hitbox_qs
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyErmilov committed Aug 13, 2023
1 parent 9b4dffd commit 0a27a34
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 26 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ members = [
"hitbox-redis",
"hitbox-stretto",
"hitbox-tower",
"hitbox-qs",
"examples",
]
4 changes: 2 additions & 2 deletions hitbox-http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ http = "0.2"
http-body = "0.4"
hitbox = { path = "../hitbox", version = "0.1" }
hitbox-backend = { path = "../hitbox-backend", version = "0.1" }
hitbox-qs = { path = "../hitbox-qs", version = "0.1" }
serde = "1.0.144"
bytes = "1"
chrono = "0.4"
hyper = { version = "0.14", features = ["stream"] }
futures = { version = "0.3", default-features = false }
actix-router = "0.5"
serde_qs = "0.12"
serde = { version = "1", features = ["derive"] }

[dev-dependencies]
tokio = { version = "1", features = ["test-util"], default-features = false }
Expand Down
13 changes: 7 additions & 6 deletions hitbox-http/src/extractors/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,17 @@ where
.parts()
.uri
.query()
.map(hitbox_qs::parse)
.map(|m| m.get(&self.name).map(hitbox_qs::Value::inner))
.map(crate::query::parse)
.map(|m| m.get(&self.name).map(crate::query::Value::inner))
.flatten()
.unwrap_or_default();
let mut parts = self.inner.get(subject).await;
for value in values {
parts.push(KeyPart {
key: self.name.clone(),
value: Some(value),
});}
parts.push(KeyPart {
key: self.name.clone(),
value: Some(value),
});
}
parts
}
}
1 change: 1 addition & 0 deletions hitbox-http/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod body;
pub mod extractors;
pub mod predicates;
mod query;
mod request;
mod response;

Expand Down
9 changes: 4 additions & 5 deletions hitbox-http/src/predicates/query.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use crate::CacheableHttpRequest;
use async_trait::async_trait;
use hitbox::predicates::{Operation, Predicate, PredicateResult};
use hitbox_qs::Value;

pub struct Query<P> {
pub name: String,
pub value: Value,
pub value: crate::query::Value,
pub operation: Operation,
inner: P,
}
Expand All @@ -21,7 +20,7 @@ where
fn query(self, name: String, value: String) -> Query<P> {
Query {
name,
value: Value::Scalar(value),
value: crate::query::Value::Scalar(value),
operation: Operation::Eq,
inner: self,
}
Expand All @@ -40,11 +39,11 @@ where
match self.inner.check(request).await {
PredicateResult::Cacheable(request) => {
let op = match self.operation {
Operation::Eq => Value::eq,
Operation::Eq => crate::query::Value::eq,
Operation::In => unimplemented!(),
};
match request.parts().uri.query() {
Some(query_string) => match hitbox_qs::parse(query_string).get(&self.name) {
Some(query_string) => match crate::query::parse(query_string).get(&self.name) {
Some(value) if op(value, &self.value) => {
PredicateResult::Cacheable(request)
}
Expand Down
2 changes: 1 addition & 1 deletion hitbox-qs/src/lib.rs → hitbox-http/src/query.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::collections::HashMap;
use serde::Deserialize;
use std::collections::HashMap;

#[derive(Debug, Deserialize, PartialEq, Eq)]
#[serde(untagged)]
Expand Down
2 changes: 1 addition & 1 deletion hitbox-http/tests/extractors/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod header;
mod query;
mod method;
mod multiple;
mod path;
mod query;
10 changes: 0 additions & 10 deletions hitbox-qs/Cargo.toml

This file was deleted.

0 comments on commit 0a27a34

Please sign in to comment.