pull/268/head
Tobi823 3 years ago
parent 94844ab435
commit e15726b0a7

@ -1,7 +1,7 @@
use encoding_rs::Encoding;
use html5ever::rcdom::RcDom;
use reqwest::blocking::Client;
use reqwest::header::{HeaderMap, HeaderValue, USER_AGENT, COOKIE};
use reqwest::header::{HeaderMap, HeaderValue, USER_AGENT, COOKIE, AUTHORIZATION};
use std::collections::HashMap;
use std::fs;
use std::io::{self, prelude::*, Error, Write};
@ -161,6 +161,16 @@ fn main() {
HeaderValue::from_str(&cookie).expect("Invalid cookie specified"),
);
}
if let Some(base_auth) = &options.base_auth {
if !base_auth.contains(":") {
panic!("base-auth doesn't have a colon. The format for base_auth must be 'username:password'.")
}
let credentials = format!("Basic {}", base64::encode(base_auth));
header_map.insert(
AUTHORIZATION,
HeaderValue::from_str(&credentials).expect("Invalid base-auth specified"),
);
}
let client = if options.timeout > 0 {
Client::builder().timeout(Duration::from_secs(options.timeout))
} else {

@ -24,6 +24,7 @@ pub struct Options {
pub no_color: bool,
pub unwrap_noscript: bool,
pub cookie: Option<String>,
pub base_auth: Option<String>,
}
const ASCII: &'static str = " \
@ -70,6 +71,7 @@ impl Options {
.args_from_usage("-u, --user-agent=[Firefox] 'Sets custom User-Agent string'")
.args_from_usage("-v, --no-video 'Removes video sources'")
.args_from_usage("--cookie, --cookie=[UTF-8] 'Set cookies for HTTP requests. This format is being used: \"name1=value1;name2=value2\"'")
.args_from_usage("--base-auth, --base-auth=[UTF-8] 'Execute a base authorization. This format is being used: \"username:password\"'")
.arg(
Arg::with_name("target")
.required(true)
@ -127,6 +129,9 @@ impl Options {
if let Some(cookie) = app.value_of("cookie") {
options.cookie = Some(str!(cookie));
}
if let Some(base_auth) = app.value_of("base-auth") {
options.base_auth = Some(str!(base_auth))
}
options
}

Loading…
Cancel
Save