read X-Forwarded-For header from trusted proxies
This commit is contained in:
parent
f5ef251458
commit
d66b12caff
2 changed files with 57 additions and 10 deletions
21
src/main.rs
21
src/main.rs
|
|
@ -1,5 +1,6 @@
|
|||
use std::io::{Result};
|
||||
use std::net::{ToSocketAddrs};
|
||||
use std::net::{IpAddr, ToSocketAddrs};
|
||||
use std::str::FromStr;
|
||||
use std::{env};
|
||||
|
||||
use mcstatusface::http::{HttpServer, StatusCode};
|
||||
|
|
@ -46,8 +47,22 @@ env!("CARGO_PKG_VERSION"));
|
|||
|
||||
let mut address = "0.0.0.0:8080".to_string();
|
||||
if args.len() > 2 { address = args[2].to_string() }
|
||||
let trusted_proxies: Vec<IpAddr> =
|
||||
match env::var("MCSTATUSFACE_TRUSTED_PROXIES") {
|
||||
Ok(envar) => {
|
||||
let mut trusted_proxies: Vec<IpAddr> = Vec::new();
|
||||
for addr in envar.split(",") {
|
||||
match IpAddr::from_str(addr) {
|
||||
Ok(addr) => { trusted_proxies.push(addr); }
|
||||
Err(_) => {}
|
||||
}
|
||||
}
|
||||
trusted_proxies
|
||||
}
|
||||
Err(_) => { vec![] }
|
||||
};
|
||||
|
||||
HttpServer::new(address, 64).start(|request, mut response| {
|
||||
HttpServer::new(address, 64, trusted_proxies).start(|request, mut response| {
|
||||
response.status(StatusCode::OK);
|
||||
response.set_header("Content-Type", "text/plain".to_string());
|
||||
response.set_header("x-powered-by", "GIRL FUEL".to_string());
|
||||
|
|
@ -132,7 +147,7 @@ env!("CARGO_PKG_VERSION"));
|
|||
// JSON response
|
||||
match request.query().get("s") {
|
||||
None => {
|
||||
response.status(StatusCode::BadRequest);
|
||||
response.status(StatusCode::OK);
|
||||
response.body("?s=<server address>\n".to_string());
|
||||
return response.send();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue