Skip to content

Commit

Permalink
Add support for using proxies.
Browse files Browse the repository at this point in the history
  • Loading branch information
FireMasterK committed Aug 21, 2023
1 parent ab32f6a commit 63953d2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
17 changes: 15 additions & 2 deletions 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
Expand Up @@ -15,7 +15,7 @@ qstring = "0.7.2"
ravif = { version = "0.11.2", optional = true }
rgb = { version = "0.8.36", optional = true }
regex = "1.9.3"
reqwest = { version = "0.11.19", features = ["rustls-tls", "stream", "brotli", "gzip"], default-features = false }
reqwest = { version = "0.11.19", features = ["rustls-tls", "stream", "brotli", "gzip", "socks"], default-features = false }
tokio = { version = "1.32.0", features = ["full"] }

[features]
Expand Down
26 changes: 23 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::env;
use std::error::Error;

use actix_web::{App, HttpRequest, HttpResponse, HttpResponseBuilder, HttpServer, web};
use actix_web::http::Method;
use actix_web::{web, App, HttpRequest, HttpResponse, HttpResponseBuilder, HttpServer};
use mimalloc::MiMalloc;
use once_cell::sync::Lazy;
use qstring::QString;
Expand All @@ -27,8 +27,8 @@ async fn main() -> std::io::Result<()> {
let bind = env::var("BIND").unwrap_or_else(|_| "0.0.0.0:8080".to_string());
server.bind(bind)?
}
.run()
.await
.run()
.await
}

static RE_DOMAIN: Lazy<Regex> =
Expand All @@ -41,6 +41,26 @@ static CLIENT: Lazy<Client> = Lazy::new(|| {
let builder = Client::builder()
.user_agent("Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101 Firefox/102.0");

let proxy = if let Ok(proxy) = env::var("PROXY") {
Some(reqwest::Proxy::all(proxy).unwrap())
} else {
None
};

if proxy.is_some() {
// proxy basic auth
let builder = if let Ok(proxy_auth_user) = env::var("PROXY_USER") {
let proxy_auth_pass = env::var("PROXY_PASS").unwrap_or_default();
builder.proxy(
proxy
.unwrap()
.basic_auth(&proxy_auth_user, &proxy_auth_pass),
)
} else {
builder.proxy(proxy.unwrap())
};
}

if env::var("IPV4_ONLY").is_ok() {
builder
.local_address(Some("0.0.0.0".parse().unwrap()))
Expand Down

0 comments on commit 63953d2

Please sign in to comment.