Skip to content

Commit

Permalink
fix: fix multi host for location
Browse files Browse the repository at this point in the history
  • Loading branch information
vicanso committed Apr 4, 2024
1 parent ed7bb99 commit 566876c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pingap"
version = "0.1.10"
version = "0.1.11"
authors = ["Tree Xie <tree.xie@outlook.com>"]
edition = "2021"
categories = ["network-programming", "web-programming::http-server"]
Expand Down
22 changes: 11 additions & 11 deletions src/proxy/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,13 @@ impl Location {
reg_rewrite = Some((re, value.to_string()));
}
}

let hosts: Vec<String> = conf
.host
.clone()
.unwrap_or_default()
.split(',')
.map(|item| item.trim().to_string())
.collect();
let mut hosts = vec![];
for item in conf.host.clone().unwrap_or_default().split(',') {
let host = item.trim().to_string();
if !host.is_empty() {
hosts.push(host);
}
}

let path = conf.path.clone().unwrap_or_default();
Ok(Location {
Expand Down Expand Up @@ -132,10 +131,11 @@ impl Location {
}
}

if !self.hosts.is_empty() && !self.hosts.iter().any(|item| item == host) {
return false;
if self.hosts.is_empty() {
return true;
}
true

self.hosts.iter().any(|item| item == host)
}
/// Rewrites the path by the rule and returns the new path.
/// If the rule is not exists, returns `None`.
Expand Down

0 comments on commit 566876c

Please sign in to comment.