Add option to disable ipv6.

This commit is contained in:
Kavin 2022-11-02 20:43:17 +00:00
parent f44df15206
commit dafafaf418
No known key found for this signature in database
GPG key ID: 49451E4482CC5BCD

View file

@ -34,7 +34,19 @@ lazy_static!(
);
lazy_static!(
static ref CLIENT: Client = Client::new();
static ref CLIENT: Client = {
let builder = Client::builder()
.user_agent("Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0");
if env::var("IPV4_ONLY").is_ok() {
builder
.local_address(Some("0.0.0.0".parse().unwrap()))
.build()
.unwrap()
} else {
builder.build().unwrap()
}
};
);
const ALLOWED_DOMAINS: [&str; 7] = [
@ -121,8 +133,6 @@ async fn index(req: HttpRequest) -> Result<HttpResponse, Box<dyn Error>> {
let request_headers = request.headers_mut();
request_headers.insert("User-Agent", "Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0".parse().unwrap());
for (key, value) in req.headers() {
if is_header_allowed(key.as_str()) {
request_headers.insert(key.clone(), value.clone());