Added proxy support

This commit is contained in:
Craeckie 2021-04-13 13:01:22 +02:00
parent 652fdd91a4
commit af094de705
3 changed files with 26 additions and 4 deletions

13
Cargo.lock generated
View File

@ -1104,6 +1104,7 @@ dependencies = [
"time", "time",
"tokio", "tokio",
"tokio-rustls", "tokio-rustls",
"tokio-socks",
"tokio-util", "tokio-util",
"url", "url",
"wasm-bindgen", "wasm-bindgen",
@ -1597,6 +1598,18 @@ dependencies = [
"webpki", "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]] [[package]]
name = "tokio-util" name = "tokio-util"
version = "0.6.5" version = "0.6.5"

View File

@ -8,7 +8,7 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [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 = { version = "1.0.2", features = ["fs", "macros", "net", "rt-multi-thread"] }
tokio-util = { version = "0.6.1", features = ["io"] } tokio-util = { version = "0.6.1", features = ["io"] }
serde_json = "1.0.51" serde_json = "1.0.51"

View File

@ -6,7 +6,7 @@ use ignore::gitignore::Gitignore;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use parking_lot::Mutex; use parking_lot::Mutex;
use regex::Regex; use regex::Regex;
use reqwest::Client; use reqwest::{Client, Proxy};
use scraper::{ElementRef, Html, Selector}; use scraper::{ElementRef, Html, Selector};
use serde_json::json; use serde_json::json;
use structopt::StructOpt; use structopt::StructOpt;
@ -653,6 +653,10 @@ struct Opt {
/// Parallel download jobs /// Parallel download jobs
#[structopt(short, long, default_value = "1")] #[structopt(short, long, default_value = "1")]
jobs: usize, jobs: usize,
/// Proxy, e.g. socks5://127.0.0.1:1080
#[structopt(short, long, default_value = "")]
proxy: String,
} }
struct ILIAS { struct ILIAS {
@ -668,9 +672,14 @@ impl ILIAS {
async fn login<S1: Into<String>, S2: Into<String>>(opt: Opt, user: S1, pass: S2, ignore: Gitignore) -> Result<Self> { async fn login<S1: Into<String>, S2: Into<String>>(opt: Opt, user: S1, pass: S2, ignore: Gitignore) -> Result<Self> {
let user = user.into(); let user = user.into();
let pass = pass.into(); let pass = pass.into();
let client = Client::builder() let mut builder = Client::builder()
.cookie_store(true) .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 // timeout is infinite by default
.build()?; .build()?;
let this = ILIAS { let this = ILIAS {