Skip to content

Commit

Permalink
support filtering on multiple alternatives of same proxy property
Browse files Browse the repository at this point in the history
Closes #210
  • Loading branch information
glendc committed May 23, 2024
1 parent f535003 commit 9b19ad2
Show file tree
Hide file tree
Showing 16 changed files with 402 additions and 196 deletions.
29 changes: 15 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ rustls-pemfile = "2.1"
rustversion = "1.0.9"
serde = "1.0"
serde_json = "1.0"
serde_urlencoded = "0.7"
serde_html_form = "0.2"
syn = "2.0"
sync_wrapper = "1.0"
tempfile = "3.10"
Expand Down Expand Up @@ -142,8 +142,8 @@ rustls = { workspace = true }
rustls-native-certs = { workspace = true }
rustls-pemfile = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_html_form = { workspace = true }
serde_json = { workspace = true }
serde_urlencoded = { workspace = true }
sync_wrapper = { workspace = true }
tokio = { workspace = true, features = ["macros", "fs"] }
tokio-graceful = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion rama-fp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ argh = { workspace = true }
base64 = { workspace = true }
rama = { version = "0.2", path = "..", features = ["full"] }
serde = { workspace = true }
serde_html_form = { workspace = true }
serde_json = { workspace = true }
serde_urlencoded = { workspace = true }
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
tracing = { workspace = true }
tracing-subscriber = { workspace = true, features = ["env-filter"] }
Expand Down
4 changes: 2 additions & 2 deletions src/http/client/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ where
/// [`Body`]: crate::http::Body
pub fn form<T: serde::Serialize + ?Sized>(mut self, form: &T) -> Self {
self.state = match self.state {
RequestBuilderState::PreBody(mut builder) => match serde_urlencoded::to_string(form) {
RequestBuilderState::PreBody(mut builder) => match serde_html_form::to_string(form) {
Ok(body) => {
let builder = match builder.headers_mut() {
Some(headers) => {
Expand Down Expand Up @@ -547,7 +547,7 @@ where
}
Err(err) => RequestBuilderState::Error(HttpClientError::from_std(err)),
},
RequestBuilderState::PostBody(mut req) => match serde_urlencoded::to_string(form) {
RequestBuilderState::PostBody(mut req) => match serde_html_form::to_string(form) {
Ok(body) => {
if !req
.headers()
Expand Down
2 changes: 1 addition & 1 deletion src/http/layer/header_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ where
G: HeaderValueGetter,
{
let value = request.header_str(header_name)?;
let config = serde_urlencoded::from_str::<T>(value)
let config = serde_html_form::from_str::<T>(value)
.map_err(|_| HeaderValueErr::HeaderInvalid(header_name.as_str().to_owned()))?;
Ok(config)
}
Expand Down
2 changes: 1 addition & 1 deletion src/http/layer/proxy_auth/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ mod test {
assert_eq!(&auth, c);

let filter: &ProxyFilter = ext.get().unwrap();
assert_eq!(filter.country, Some("us".into()));
assert_eq!(filter.country, Some(vec!["us".into()]));
}

#[tokio::test]
Expand Down
4 changes: 2 additions & 2 deletions src/http/response/form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ where
T: Serialize,
{
fn into_response(self) -> Response {
match serde_urlencoded::to_string(&self.0) {
match serde_html_form::to_string(&self.0) {
Ok(body) => (
[(CONTENT_TYPE, mime::APPLICATION_WWW_FORM_URLENCODED.as_ref())],
body,
Expand All @@ -98,7 +98,7 @@ where
type Error = OpaqueError;

fn try_into(self) -> Result<Body, Self::Error> {
match serde_urlencoded::to_string(&self.0) {
match serde_html_form::to_string(&self.0) {
Ok(body) => Ok(body.into()),
Err(err) => Err(OpaqueError::from_std(err)),
}
Expand Down
4 changes: 2 additions & 2 deletions src/http/service/web/endpoint/extract/body/form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ where
async fn from_request(_ctx: Context<S>, req: Request) -> Result<Self, Self::Rejection> {
if req.method() == Method::GET {
let query = req.uri().query().unwrap_or_default();
let value = match serde_urlencoded::from_bytes(query.as_bytes()) {
let value = match serde_html_form::from_bytes(query.as_bytes()) {
Ok(value) => value,
Err(err) => return Err(FailedToDeserializeForm::from_err(err).into()),
};
Expand All @@ -61,7 +61,7 @@ where
let body = req.into_body();
match body.collect().await {
Ok(c) => {
let value = match serde_urlencoded::from_bytes(&c.to_bytes()) {
let value = match serde_html_form::from_bytes(&c.to_bytes()) {
Ok(value) => value,
Err(err) => return Err(FailedToDeserializeForm::from_err(err).into()),
};
Expand Down
2 changes: 1 addition & 1 deletion src/http/service/web/endpoint/extract/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ where
async fn from_request_parts(_ctx: &Context<S>, parts: &Parts) -> Result<Self, Self::Rejection> {
let query = parts.uri.query().unwrap_or_default();
let params =
serde_urlencoded::from_str(query).map_err(FailedToDeserializeQueryString::from_err)?;
serde_html_form::from_str(query).map_err(FailedToDeserializeQueryString::from_err)?;
Ok(Query(params))
}
}
Expand Down
Loading

0 comments on commit 9b19ad2

Please sign in to comment.