Skip to content

Add basic proxy support #123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ This is the list of all features supported by the current version of `drill`:
- **CSV support:** read CSV files and build N requests fill dynamic interpolations with CSV data.
- **HTTP methods:** build request with different http methods like GET, POST, PUT, PATCH, HEAD or DELETE.
- **Cookie support:** create benchmarks with sessions because cookies are propagates between requests.
- **Proxy support:** run benchmarks through proxies.
- **Stats:** get nice statistics about all the requests. Example: [cookies.yml](./example/cookies.yml)
- **Thresholds:** compare the current benchmark performance against a stored one session and fail if a threshold is exceeded.

Expand All @@ -213,7 +214,7 @@ production environments.
Full list of cli options, which is available under `drill --help`

```
drill 0.7.1
drill 0.7.2
HTTP load testing application written in Rust inspired by Ansible syntax

USAGE:
Expand All @@ -232,6 +233,7 @@ FLAGS:
OPTIONS:
-b, --benchmark <benchmark> Sets the benchmark file
-c, --compare <compare> Sets a compare file
-p, --proxy <proxy> [protocol://]host[:port] Use this proxy
-r, --report <report> Sets a report file
-t, --threshold <threshold> Sets a threshold value in ms amongst the compared file
-o, --timeout <timeout> Set timeout in seconds for all requests
Expand Down
14 changes: 13 additions & 1 deletion src/actions/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,19 @@ impl Request {
// Resolve the body
let (client, request) = {
let mut pool2 = pool.lock().unwrap();
let client = pool2.entry(domain).or_insert_with(|| ClientBuilder::default().danger_accept_invalid_certs(config.no_check_certificate).build().unwrap());
let client = pool2.entry(domain).or_insert_with(|| {
let builder = ClientBuilder::default().danger_accept_invalid_certs(config.no_check_certificate);

let proxied_builder = if config.proxy.is_empty() {
builder.no_proxy()
} else {
let proxy = reqwest::Proxy::all(&config.proxy).expect("Unable to build proxy connector");

builder.proxy(proxy)
};

proxied_builder.build().unwrap()
});

let request = if let Some(body) = self.body.as_ref() {
interpolated_body = uninterpolator.get_or_insert(interpolator::Interpolator::new(context)).resolve(body, !config.relaxed_interpolations);
Expand Down
4 changes: 2 additions & 2 deletions src/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ fn join<S: ToString>(l: Vec<S>, sep: &str) -> String {
)
}

pub fn execute(benchmark_path: &str, report_path_option: Option<&str>, relaxed_interpolations: bool, no_check_certificate: bool, quiet: bool, nanosec: bool, timeout: Option<&str>, verbose: bool) -> BenchmarkResult {
let config = Arc::new(Config::new(benchmark_path, relaxed_interpolations, no_check_certificate, quiet, nanosec, timeout.map_or(10, |t| t.parse().unwrap_or(10)), verbose));
pub fn execute(benchmark_path: &str, report_path_option: Option<&str>, relaxed_interpolations: bool, no_check_certificate: bool, proxy: &str, quiet: bool, nanosec: bool, timeout: Option<&str>, verbose: bool) -> BenchmarkResult {
let config = Arc::new(Config::new(benchmark_path, relaxed_interpolations, no_check_certificate, proxy, quiet, nanosec, timeout.map_or(10, |t| t.parse().unwrap_or(10)), verbose));

if report_path_option.is_some() {
println!("{}: {}. Ignoring {} and {} properties...", "Report mode".yellow(), "on".purple(), "concurrency".yellow(), "iterations".yellow());
Expand Down
4 changes: 3 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ pub struct Config {
pub nanosec: bool,
pub timeout: u64,
pub verbose: bool,
pub proxy: String,
}

impl Config {
pub fn new(path: &str, relaxed_interpolations: bool, no_check_certificate: bool, quiet: bool, nanosec: bool, timeout: u64, verbose: bool) -> Config {
pub fn new(path: &str, relaxed_interpolations: bool, no_check_certificate: bool, proxy: &str, quiet: bool, nanosec: bool, timeout: u64, verbose: bool) -> Config {
let config_file = reader::read_file(path);

let config_docs = YamlLoader::load_from_str(config_file.as_str()).unwrap();
Expand Down Expand Up @@ -50,6 +51,7 @@ impl Config {
nanosec,
timeout,
verbose,
proxy: proxy.to_string(),
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ fn main() {
let threshold_option = matches.value_of("threshold");
let no_check_certificate = matches.is_present("no-check-certificate");
let relaxed_interpolations = matches.is_present("relaxed-interpolations");
let proxy = matches.value_of("proxy").unwrap_or("");
let quiet = matches.is_present("quiet");
let nanosec = matches.is_present("nanosec");
let timeout = matches.value_of("timeout");
let verbose = matches.is_present("verbose");
#[cfg(windows)]
let _ = control::set_virtual_terminal(true);

let benchmark_result = benchmark::execute(benchmark_file, report_path_option, relaxed_interpolations, no_check_certificate, quiet, nanosec, timeout, verbose);
let benchmark_result = benchmark::execute(benchmark_file, report_path_option, relaxed_interpolations, no_check_certificate, proxy, quiet, nanosec, timeout, verbose);
let list_reports = benchmark_result.reports;
let duration = benchmark_result.duration;

Expand All @@ -53,6 +54,7 @@ fn app_args<'a>() -> clap::ArgMatches<'a> {
.arg(Arg::with_name("threshold").short("t").long("threshold").help("Sets a threshold value in ms amongst the compared file").takes_value(true).conflicts_with("report"))
.arg(Arg::with_name("relaxed-interpolations").long("relaxed-interpolations").help("Do not panic if an interpolation is not present. (Not recommended)").takes_value(false))
.arg(Arg::with_name("no-check-certificate").long("no-check-certificate").help("Disables SSL certification check. (Not recommended)").takes_value(false))
.arg(Arg::with_name("proxy").short("p").long("proxy").help("[protocol://]host[:port] Use this proxy").takes_value(true))
.arg(Arg::with_name("quiet").short("q").long("quiet").help("Disables output").takes_value(false))
.arg(Arg::with_name("timeout").short("o").long("timeout").help("Set timeout in seconds for all requests").takes_value(true))
.arg(Arg::with_name("nanosec").short("n").long("nanosec").help("Shows statistics in nanoseconds").takes_value(false))
Expand Down