Skip to content

Commit

Permalink
disable dot in rand_regex
Browse files Browse the repository at this point in the history
  • Loading branch information
hatoo committed Jun 19, 2023
1 parent d036c13 commit 0022900
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ lazy_static = "1.4.0"
rand = "0.8"
trust-dns-resolver = "0.22.0"
rand_regex = "0.15.1"
regex-syntax = "0.6.22"

[target.'cfg(unix)'.dependencies]
rlimit = "0.9.0"
Expand Down
16 changes: 14 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Examples: -z 10s -z 3m.",
#[clap(help = "Rate limit for all, in queries per second (QPS)", short = 'q')]
query_per_second: Option<usize>,
#[clap(
help = "Generate URL by rand_regex crate for each query e.g. http://localhost/[a-z][a-z][0-9]. Currently dynamic scheme, host and port with keep-alive are not works well. See https://docs.rs/rand_regex/latest/rand_regex/struct.Regex.html for details of syntax.",
help = "Generate URL by rand_regex crate but dot is disabled for each query e.g. http://127.0.0.1/[a-z][a-z][0-9]. Currently dynamic scheme, host and port with keep-alive are not works well. See https://docs.rs/rand_regex/latest/rand_regex/struct.Regex.html for details of syntax.",
default_value = "false",
long
)]
Expand Down Expand Up @@ -197,7 +197,19 @@ async fn main() -> anyhow::Result<()> {
};

let url_generator = if opts.rand_regex_url {
UrlGenerator::new_dynamic(Regex::compile(&opts.url, opts.max_repeat)?)
// Almost URL has dot in domain, so disable dot in regex for convenience.
let dot_disabled: String = opts
.url
.chars()
.map(|c| {
if c == '.' {
regex_syntax::escape(".")
} else {
c.to_string()
}
})
.collect();
UrlGenerator::new_dynamic(Regex::compile(&dot_disabled, opts.max_repeat)?)
} else {
UrlGenerator::new_static(Uri::from_str(&opts.url)?)
};
Expand Down
2 changes: 1 addition & 1 deletion tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ async fn get_path_rand_regex(p: &'static str) -> String {
Command::cargo_bin("oha")
.unwrap()
.args(["-n", "1", "--no-tui", "--rand-regex-url"])
.arg(format!(r"http://127\.0\.0\.1:{port}/{p}"))
.arg(format!(r"http://127.0.0.1:{port}/{p}"))
.assert()
.success();
})
Expand Down

0 comments on commit 0022900

Please sign in to comment.