Skip to content

Rename blacklist_ips to block_ips #1533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ impl AroundMiddleware for BlockIps {

impl Handler for BlockIps {
fn call(&self, req: &mut dyn Request) -> Result<Response, Box<dyn Error + Send>> {
let has_blacklisted_ip = req
let has_blocked_ip = req
.headers()
.find("X-Forwarded-For")
.unwrap()
.iter()
.any(|v| v.split(", ").any(|ip| self.ips.iter().any(|x| x == ip)));
if has_blacklisted_ip {
if has_blocked_ip {
let body = format!(
"We are unable to process your request at this time. \
Please open an issue at https://github.com/rust-lang/crates.io \
Expand Down
6 changes: 3 additions & 3 deletions src/middleware/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub use self::security_headers::SecurityHeaders;
pub use self::static_or_continue::StaticOrContinue;

pub mod app;
mod blacklist_ips;
mod block_ips;
pub mod current_user;
mod debug;
mod ember_index_rewrite;
Expand Down Expand Up @@ -81,9 +81,9 @@ pub fn build_middleware(app: Arc<App>, endpoints: R404) -> MiddlewareBuilder {

m.around(Head::default());

if let Ok(ip_list) = env::var("BLACKLISTED_IPS") {
if let Ok(ip_list) = env::var("BLOCKED_IPS") {
let ips = ip_list.split(',').map(String::from).collect();
m.around(blacklist_ips::BlockIps::new(ips));
m.around(block_ips::BlockIps::new(ips));
}

if env != Env::Test {
Expand Down