diff --git a/Cargo.lock b/Cargo.lock index 6a905c0..c812132 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1104,6 +1104,7 @@ dependencies = [ "time", "tokio", "tokio-rustls", + "tokio-socks", "tokio-util", "url", "wasm-bindgen", @@ -1597,6 +1598,18 @@ dependencies = [ "webpki", ] +[[package]] +name = "tokio-socks" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51165dfa029d2a65969413a6cc96f354b86b464498702f174a4efa13608fd8c0" +dependencies = [ + "either", + "futures-util", + "thiserror", + "tokio", +] + [[package]] name = "tokio-util" version = "0.6.5" diff --git a/Cargo.toml b/Cargo.toml index ce2ec71..374a592 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -reqwest = { version = "0.11.0", default-features = false, features = ["cookies", "gzip", "json", "rustls-tls", "stream"] } +reqwest = { version = "0.11.0", default-features = false, features = ["cookies", "gzip", "json", "rustls-tls", "stream", "socks"] } tokio = { version = "1.0.2", features = ["fs", "macros", "net", "rt-multi-thread"] } tokio-util = { version = "0.6.1", features = ["io"] } serde_json = "1.0.51" diff --git a/src/main.rs b/src/main.rs index 50af630..09dcf8d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,7 @@ use ignore::gitignore::Gitignore; use lazy_static::lazy_static; use parking_lot::Mutex; use regex::Regex; -use reqwest::Client; +use reqwest::{Client, Proxy}; use scraper::{ElementRef, Html, Selector}; use serde_json::json; use structopt::StructOpt; @@ -653,6 +653,10 @@ struct Opt { /// Parallel download jobs #[structopt(short, long, default_value = "1")] jobs: usize, + + /// Proxy, e.g. socks5://127.0.0.1:1080 + #[structopt(short, long, default_value = "")] + proxy: String, } struct ILIAS { @@ -668,9 +672,14 @@ impl ILIAS { async fn login, S2: Into>(opt: Opt, user: S1, pass: S2, ignore: Gitignore) -> Result { let user = user.into(); let pass = pass.into(); - let client = Client::builder() + let mut builder = Client::builder() .cookie_store(true) - .user_agent(concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"))) + .user_agent(concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"))); + if opt.proxy != "" { + let proxy = Proxy::all(&opt.proxy)?; + builder = builder.proxy(proxy); + } + let client = builder // timeout is infinite by default .build()?; let this = ILIAS {