mirror of
https://github.com/Orange-OpenSource/hurl.git
synced 2024-09-11 05:35:53 +03:00
feat: File size limits
This commit is contained in:
parent
72967570a8
commit
7787d711a3
@ -976,6 +976,7 @@ will follow a redirection only for the second entry.
|
||||
| <a href="#key" id="key"><code>--key <KEY></code></a> | Private key file name.<br> |
|
||||
| <a href="#location" id="location"><code>-L, --location</code></a> | Follow redirect. To limit the amount of redirects to follow use the [`--max-redirs`](#max-redirs) option<br> |
|
||||
| <a href="#location-trusted" id="location-trusted"><code>--location-trusted</code></a> | Like [`-L, --location`](#location), but allows sending the name + password to all hosts that the site may redirect to.<br>This may or may not introduce a security breach if the site redirects you to a site to which you send your authentication info (which is plaintext in the case of HTTP Basic authentication).<br> |
|
||||
| <a href="#max-filesize" id="max-filesize"><code>--max-filesize <BYTES></code></a> | Specify the maximum size (in bytes) of a file to download. If the file requested is larger than this value, the transfer does not start.<br> |
|
||||
| <a href="#max-redirs" id="max-redirs"><code>--max-redirs <NUM></code></a> | Set maximum number of redirection-followings allowed<br><br>By default, the limit is set to 50 redirections. Set this option to -1 to make it unlimited.<br> |
|
||||
| <a href="#max-time" id="max-time"><code>-m, --max-time <SECONDS></code></a> | Maximum time in seconds that you allow a request/response to take. This is the standard timeout.<br><br>See also [`--connect-timeout`](#connect-timeout).<br><br>This is a cli-only option.<br> |
|
||||
| <a href="#netrc" id="netrc"><code>-n, --netrc</code></a> | Scan the .netrc file in the user's home directory for the username and password.<br><br>See also [`--netrc-file`](#netrc-file) and [`--netrc-optional`](#netrc-optional).<br> |
|
||||
|
@ -46,6 +46,7 @@ _hurl() {
|
||||
'(-6 --ipv6)'{-6,--ipv6}'[Tell Hurl to use IPv6 addresses only when resolving host names, and not for example try IPv4]' \
|
||||
'--jobs[(Experimental) Maximum number of parallel jobs]: :' \
|
||||
'--json[Output each Hurl file result to JSON]' \
|
||||
'--max-filesize[Specify the maximum size (in bytes) of a file to download]: :' \
|
||||
'--max-redirs[Maximum number of redirects allowed, -1 for unlimited redirects]: :' \
|
||||
'(-m --max-time)'{-m,--max-time}'[Maximum time allowed for the transfer]: :' \
|
||||
'(-n --netrc)'{-n,--netrc}'[Must read .netrc for username and password]' \
|
||||
|
@ -51,6 +51,7 @@ Register-ArgumentCompleter -Native -CommandName 'hurl' -ScriptBlock {
|
||||
[CompletionResult]::new('--ipv6', 'ipv6', [CompletionResultType]::ParameterName, 'Tell Hurl to use IPv6 addresses only when resolving host names, and not for example try IPv4')
|
||||
[CompletionResult]::new('--jobs', 'jobs', [CompletionResultType]::ParameterName, '(Experimental) Maximum number of parallel jobs')
|
||||
[CompletionResult]::new('--json', 'json', [CompletionResultType]::ParameterName, 'Output each Hurl file result to JSON')
|
||||
[CompletionResult]::new('--max-filesize', 'max-filesize', [CompletionResultType]::ParameterName, 'Specify the maximum size (in bytes) of a file to download')
|
||||
[CompletionResult]::new('--max-redirs', 'max-redirs', [CompletionResultType]::ParameterName, 'Maximum number of redirects allowed, -1 for unlimited redirects')
|
||||
[CompletionResult]::new('--max-time', 'max-time', [CompletionResultType]::ParameterName, 'Maximum time allowed for the transfer')
|
||||
[CompletionResult]::new('--netrc', 'netrc', [CompletionResultType]::ParameterName, 'Must read .netrc for username and password')
|
||||
|
@ -5,7 +5,7 @@ _hurl()
|
||||
_init_completion || return
|
||||
|
||||
if [[ $cur == -* ]]; then
|
||||
COMPREPLY=($(compgen -W '--aws-sigv4 --cacert --cert --key --color --compressed --connect-timeout --connect-to --continue-on-error --cookie --cookie-jar --delay --error-format --fail-at-end --file-root --location --location-trusted --from-entry --glob --http1.0 --http1.1 --http2 --http3 --ignore-asserts --include --insecure --interactive --ipv4 --ipv6 --jobs --json --max-redirs --max-time --netrc --netrc-file --netrc-optional --no-color --no-output --noproxy --output --parallel --path-as-is --proxy --report-html --report-junit --report-tap --resolve --retry --retry-interval --ssl-no-revoke --test --to-entry --unix-socket --user --user-agent --variable --variables-file --verbose --very-verbose --help --version' -- "$cur"))
|
||||
COMPREPLY=($(compgen -W '--aws-sigv4 --cacert --cert --key --color --compressed --connect-timeout --connect-to --continue-on-error --cookie --cookie-jar --delay --error-format --fail-at-end --file-root --location --location-trusted --from-entry --glob --http1.0 --http1.1 --http2 --http3 --ignore-asserts --include --insecure --interactive --ipv4 --ipv6 --jobs --json --max-filesize --max-redirs --max-time --netrc --netrc-file --netrc-optional --no-color --no-output --noproxy --output --parallel --path-as-is --proxy --report-html --report-junit --report-tap --resolve --retry --retry-interval --ssl-no-revoke --test --to-entry --unix-socket --user --user-agent --variable --variables-file --verbose --very-verbose --help --version' -- "$cur"))
|
||||
return
|
||||
fi
|
||||
|
||||
|
@ -29,6 +29,7 @@ complete -c hurl -l ipv4 -d 'Tell Hurl to use IPv4 addresses only when resolving
|
||||
complete -c hurl -l ipv6 -d 'Tell Hurl to use IPv6 addresses only when resolving host names, and not for example try IPv4'
|
||||
complete -c hurl -l jobs -d '(Experimental) Maximum number of parallel jobs'
|
||||
complete -c hurl -l json -d 'Output each Hurl file result to JSON'
|
||||
complete -c hurl -l max-filesize -d 'Specify the maximum size (in bytes) of a file to download'
|
||||
complete -c hurl -l max-redirs -d 'Maximum number of redirects allowed, -1 for unlimited redirects'
|
||||
complete -c hurl -l max-time -d 'Maximum time allowed for the transfer'
|
||||
complete -c hurl -l netrc -d 'Must read .netrc for username and password'
|
||||
|
@ -177,6 +177,7 @@ will follow a redirection only for the second entry.
|
||||
| <a href="#key" id="key"><code>--key <KEY></code></a> | Private key file name.<br> |
|
||||
| <a href="#location" id="location"><code>-L, --location</code></a> | Follow redirect. To limit the amount of redirects to follow use the [`--max-redirs`](#max-redirs) option<br> |
|
||||
| <a href="#location-trusted" id="location-trusted"><code>--location-trusted</code></a> | Like [`-L, --location`](#location), but allows sending the name + password to all hosts that the site may redirect to.<br>This may or may not introduce a security breach if the site redirects you to a site to which you send your authentication info (which is plaintext in the case of HTTP Basic authentication).<br> |
|
||||
| <a href="#max-filesize" id="max-filesize"><code>--max-filesize <BYTES></code></a> | Specify the maximum size (in bytes) of a file to download. If the file requested is larger than this value, the transfer does not start.<br> |
|
||||
| <a href="#max-redirs" id="max-redirs"><code>--max-redirs <NUM></code></a> | Set maximum number of redirection-followings allowed<br><br>By default, the limit is set to 50 redirections. Set this option to -1 to make it unlimited.<br> |
|
||||
| <a href="#max-time" id="max-time"><code>-m, --max-time <SECONDS></code></a> | Maximum time in seconds that you allow a request/response to take. This is the standard timeout.<br><br>See also [`--connect-timeout`](#connect-timeout).<br><br>This is a cli-only option.<br> |
|
||||
| <a href="#netrc" id="netrc"><code>-n, --netrc</code></a> | Scan the .netrc file in the user's home directory for the username and password.<br><br>See also [`--netrc-file`](#netrc-file) and [`--netrc-optional`](#netrc-optional).<br> |
|
||||
|
@ -1,4 +1,4 @@
|
||||
.TH hurl 1 "26 Mar 2024" "hurl 4.3.0-SNAPSHOT" " Hurl Manual"
|
||||
.TH hurl 1 "01 Apr 2024" "hurl 4.3.0-SNAPSHOT" " Hurl Manual"
|
||||
.SH NAME
|
||||
|
||||
hurl - run and test HTTP requests.
|
||||
@ -295,6 +295,10 @@ Follow redirect. To limit the amount of redirects to follow use the \fI--max-red
|
||||
Like \fI-L, --location\fP, but allows sending the name + password to all hosts that the site may redirect to.
|
||||
This may or may not introduce a security breach if the site redirects you to a site to which you send your authentication info (which is plaintext in the case of HTTP Basic authentication).
|
||||
|
||||
.IP "--max-filesize <BYTES> "
|
||||
|
||||
Specify the maximum size (in bytes) of a file to download. If the file requested is larger than this value, the transfer does not start.
|
||||
|
||||
.IP "--max-redirs <NUM> "
|
||||
|
||||
Set maximum number of redirection-followings allowed
|
||||
|
@ -314,6 +314,10 @@ Follow redirect. To limit the amount of redirects to follow use the [`--max-redi
|
||||
Like [`-L, --location`](#location), but allows sending the name + password to all hosts that the site may redirect to.
|
||||
This may or may not introduce a security breach if the site redirects you to a site to which you send your authentication info (which is plaintext in the case of HTTP Basic authentication).
|
||||
|
||||
### --max-filesize <BYTES> {#max-filesize}
|
||||
|
||||
Specify the maximum size (in bytes) of a file to download. If the file requested is larger than this value, the transfer does not start.
|
||||
|
||||
### --max-redirs <NUM> {#max-redirs}
|
||||
|
||||
Set maximum number of redirection-followings allowed
|
||||
|
@ -1,4 +1,4 @@
|
||||
.TH hurl 1 "26 Mar 2024" "hurl 4.3.0-SNAPSHOT" " Hurl Manual"
|
||||
.TH hurl 1 "01 Apr 2024" "hurl 4.3.0-SNAPSHOT" " Hurl Manual"
|
||||
.SH NAME
|
||||
|
||||
hurlfmt - format Hurl files
|
||||
|
7
docs/spec/options/hurl/max_filesize.option
Normal file
7
docs/spec/options/hurl/max_filesize.option
Normal file
@ -0,0 +1,7 @@
|
||||
name: max_filesize
|
||||
long: max-filesize
|
||||
value: BYTES
|
||||
value_parser: clap::value_parser!(u64)
|
||||
help: Specify the maximum size (in bytes) of a file to download
|
||||
---
|
||||
Specify the maximum size (in bytes) of a file to download. If the file requested is larger than this value, the transfer does not start.
|
@ -67,6 +67,8 @@ Options:
|
||||
IPv4
|
||||
--json
|
||||
Output each Hurl file result to JSON
|
||||
--max-filesize <BYTES>
|
||||
Specify the maximum size (in bytes) of a file to download
|
||||
--max-redirs <NUM>
|
||||
Maximum number of redirects allowed, -1 for unlimited redirects [default: 50]
|
||||
-m, --max-time <SECONDS>
|
||||
|
@ -968,6 +968,7 @@ will follow a redirection only for the second entry.
|
||||
| <a href="#key" id="key"><code>--key <KEY></code></a> | Private key file name.<br> |
|
||||
| <a href="#location" id="location"><code>-L, --location</code></a> | Follow redirect. To limit the amount of redirects to follow use the [`--max-redirs`](#max-redirs) option<br> |
|
||||
| <a href="#location-trusted" id="location-trusted"><code>--location-trusted</code></a> | Like [`-L, --location`](#location), but allows sending the name + password to all hosts that the site may redirect to.<br>This may or may not introduce a security breach if the site redirects you to a site to which you send your authentication info (which is plaintext in the case of HTTP Basic authentication).<br> |
|
||||
| <a href="#max-filesize" id="max-filesize"><code>--max-filesize <BYTES></code></a> | Specify the maximum size (in bytes) of a file to download. If the file requested is larger than this value, the transfer does not start.<br> |
|
||||
| <a href="#max-redirs" id="max-redirs"><code>--max-redirs <NUM></code></a> | Set maximum number of redirection-followings allowed<br><br>By default, the limit is set to 50 redirections. Set this option to -1 to make it unlimited.<br> |
|
||||
| <a href="#max-time" id="max-time"><code>-m, --max-time <SECONDS></code></a> | Maximum time in seconds that you allow a request/response to take. This is the standard timeout.<br><br>See also [`--connect-timeout`](#connect-timeout).<br><br>This is a cli-only option.<br> |
|
||||
| <a href="#netrc" id="netrc"><code>-n, --netrc</code></a> | Scan the .netrc file in the user's home directory for the username and password.<br><br>See also [`--netrc-file`](#netrc-file) and [`--netrc-optional`](#netrc-optional).<br> |
|
||||
|
@ -282,6 +282,15 @@ pub fn json() -> clap::Arg {
|
||||
.action(clap::ArgAction::SetTrue)
|
||||
}
|
||||
|
||||
pub fn max_filesize() -> clap::Arg {
|
||||
clap::Arg::new("max_filesize")
|
||||
.long("max-filesize")
|
||||
.value_name("BYTES")
|
||||
.value_parser(clap::value_parser!(u64))
|
||||
.help("Specify the maximum size (in bytes) of a file to download")
|
||||
.num_args(1)
|
||||
}
|
||||
|
||||
pub fn max_redirects() -> clap::Arg {
|
||||
clap::Arg::new("max_redirects")
|
||||
.long("max-redirs")
|
||||
|
@ -423,6 +423,10 @@ pub fn very_verbose(arg_matches: &ArgMatches) -> bool {
|
||||
has_flag(arg_matches, "very_verbose")
|
||||
}
|
||||
|
||||
pub fn max_filesize(arg_matches: &ArgMatches) -> Option<u64> {
|
||||
get::<u64>(arg_matches, "max_filesize")
|
||||
}
|
||||
|
||||
/// Returns a list of path names from the command line options `matches`.
|
||||
fn glob_files(matches: &ArgMatches) -> Result<Vec<Input>, CliOptionsError> {
|
||||
let mut all_files = vec![];
|
||||
|
@ -67,6 +67,7 @@ pub struct CliOptions {
|
||||
pub ip_resolve: Option<IpResolve>,
|
||||
pub jobs: Option<usize>,
|
||||
pub junit_file: Option<PathBuf>,
|
||||
pub max_filesize: Option<u64>,
|
||||
pub max_redirect: Option<usize>,
|
||||
pub netrc: bool,
|
||||
pub netrc_file: Option<String>,
|
||||
@ -191,6 +192,7 @@ pub fn parse() -> Result<CliOptions, CliOptionsError> {
|
||||
.arg(commands::ipv6())
|
||||
.arg(commands::jobs())
|
||||
.arg(commands::json())
|
||||
.arg(commands::max_filesize())
|
||||
.arg(commands::max_redirects())
|
||||
.arg(commands::max_time())
|
||||
.arg(commands::netrc())
|
||||
@ -264,6 +266,7 @@ fn parse_matches(arg_matches: &ArgMatches) -> Result<CliOptions, CliOptionsError
|
||||
let interactive = matches::interactive(arg_matches);
|
||||
let ip_resolve = matches::ip_resolve(arg_matches);
|
||||
let junit_file = matches::junit_file(arg_matches);
|
||||
let max_filesize = matches::max_filesize(arg_matches);
|
||||
let max_redirect = matches::max_redirect(arg_matches);
|
||||
let netrc = matches::netrc(arg_matches);
|
||||
let netrc_file = matches::netrc_file(arg_matches)?;
|
||||
@ -289,7 +292,7 @@ fn parse_matches(arg_matches: &ArgMatches) -> Result<CliOptions, CliOptionsError
|
||||
let variables = matches::variables(arg_matches)?;
|
||||
let verbose = matches::verbose(arg_matches);
|
||||
let very_verbose = matches::very_verbose(arg_matches);
|
||||
let workers = matches::jobs(arg_matches);
|
||||
let jobs = matches::jobs(arg_matches);
|
||||
Ok(CliOptions {
|
||||
aws_sigv4,
|
||||
cacert_file,
|
||||
@ -317,6 +320,7 @@ fn parse_matches(arg_matches: &ArgMatches) -> Result<CliOptions, CliOptionsError
|
||||
interactive,
|
||||
ip_resolve,
|
||||
junit_file,
|
||||
max_filesize,
|
||||
max_redirect,
|
||||
netrc,
|
||||
netrc_file,
|
||||
@ -342,7 +346,7 @@ fn parse_matches(arg_matches: &ArgMatches) -> Result<CliOptions, CliOptionsError
|
||||
variables,
|
||||
verbose,
|
||||
very_verbose,
|
||||
jobs: workers,
|
||||
jobs,
|
||||
})
|
||||
}
|
||||
|
||||
@ -389,6 +393,7 @@ impl CliOptions {
|
||||
Some(ip) => ip.into(),
|
||||
None => http::IpResolve::default(),
|
||||
};
|
||||
let max_filesize = self.max_filesize;
|
||||
let max_redirect = self.max_redirect;
|
||||
let netrc = self.netrc;
|
||||
let netrc_file = self.netrc_file.clone();
|
||||
@ -466,6 +471,7 @@ impl CliOptions {
|
||||
.ignore_asserts(ignore_asserts)
|
||||
.insecure(insecure)
|
||||
.ip_resolve(ip_resolve)
|
||||
.max_filesize(max_filesize)
|
||||
.max_redirect(max_redirect)
|
||||
.netrc(netrc)
|
||||
.netrc_file(netrc_file)
|
||||
|
@ -439,6 +439,9 @@ impl Client {
|
||||
}
|
||||
self.handle.timeout(options.timeout)?;
|
||||
self.handle.connect_timeout(options.connect_timeout)?;
|
||||
if let Some(max_filesize) = options.max_filesize {
|
||||
self.handle.max_filesize(max_filesize)?;
|
||||
}
|
||||
|
||||
self.set_ssl_options(options.ssl_no_revoke)?;
|
||||
|
||||
|
@ -37,6 +37,7 @@ pub struct ClientOptions {
|
||||
pub http_version: RequestedHttpVersion,
|
||||
pub insecure: bool,
|
||||
pub ip_resolve: IpResolve,
|
||||
pub max_filesize: Option<u64>,
|
||||
pub max_redirect: Option<usize>,
|
||||
pub netrc: bool,
|
||||
pub netrc_file: Option<String>,
|
||||
@ -77,6 +78,7 @@ impl Default for ClientOptions {
|
||||
http_version: RequestedHttpVersion::default(),
|
||||
insecure: false,
|
||||
ip_resolve: IpResolve::default(),
|
||||
max_filesize: None,
|
||||
max_redirect: Some(50),
|
||||
netrc: false,
|
||||
netrc_file: None,
|
||||
@ -152,6 +154,10 @@ impl ClientOptions {
|
||||
} else if self.follow_location {
|
||||
arguments.push("--location".to_string());
|
||||
}
|
||||
if let Some(max_filesize) = self.max_filesize {
|
||||
arguments.push("--max-filesize".to_string());
|
||||
arguments.push(max_filesize.to_string());
|
||||
}
|
||||
if self.max_redirect != ClientOptions::default().max_redirect {
|
||||
let max_redirect = match self.max_redirect {
|
||||
None => -1,
|
||||
@ -224,6 +230,7 @@ mod tests {
|
||||
http_version: RequestedHttpVersion::Http10,
|
||||
insecure: true,
|
||||
ip_resolve: IpResolve::IpV6,
|
||||
max_filesize: None,
|
||||
max_redirect: Some(10),
|
||||
netrc: false,
|
||||
netrc_file: Some("/var/run/netrc".to_string()),
|
||||
@ -233,7 +240,7 @@ mod tests {
|
||||
no_proxy: None,
|
||||
resolves: vec![
|
||||
"foo.com:80:192.168.0.1".to_string(),
|
||||
"bar.com:443:127.0.0.1".to_string()
|
||||
"bar.com:443:127.0.0.1".to_string(),
|
||||
],
|
||||
retry: Retry::None,
|
||||
ssl_no_revoke: false,
|
||||
|
@ -211,6 +211,7 @@ impl ClientOptions {
|
||||
follow_location_trusted: runner_options.follow_location_trusted,
|
||||
http_version: runner_options.http_version,
|
||||
ip_resolve: runner_options.ip_resolve,
|
||||
max_filesize: runner_options.max_filesize,
|
||||
max_redirect: runner_options.max_redirect,
|
||||
netrc: runner_options.netrc,
|
||||
netrc_file: runner_options.netrc_file.clone(),
|
||||
|
@ -42,6 +42,7 @@ pub struct RunnerOptionsBuilder {
|
||||
ignore_asserts: bool,
|
||||
insecure: bool,
|
||||
ip_resolve: IpResolve,
|
||||
max_filesize: Option<u64>,
|
||||
max_redirect: Option<usize>,
|
||||
netrc: bool,
|
||||
netrc_file: Option<String>,
|
||||
@ -85,6 +86,7 @@ impl Default for RunnerOptionsBuilder {
|
||||
ignore_asserts: false,
|
||||
insecure: false,
|
||||
ip_resolve: IpResolve::default(),
|
||||
max_filesize: None,
|
||||
max_redirect: Some(50),
|
||||
netrc: false,
|
||||
netrc_file: None,
|
||||
@ -375,6 +377,12 @@ impl RunnerOptionsBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the file size limit
|
||||
pub fn max_filesize(&mut self, max_filesize: Option<u64>) -> &mut Self {
|
||||
self.max_filesize = max_filesize;
|
||||
self
|
||||
}
|
||||
|
||||
/// Create an instance of [`RunnerOptions`].
|
||||
pub fn build(&self) -> RunnerOptions {
|
||||
RunnerOptions {
|
||||
@ -396,6 +404,7 @@ impl RunnerOptionsBuilder {
|
||||
ignore_asserts: self.ignore_asserts,
|
||||
insecure: self.insecure,
|
||||
ip_resolve: self.ip_resolve,
|
||||
max_filesize: self.max_filesize,
|
||||
max_redirect: self.max_redirect,
|
||||
netrc: self.netrc,
|
||||
netrc_file: self.netrc_file.clone(),
|
||||
@ -440,6 +449,7 @@ pub struct RunnerOptions {
|
||||
pub(crate) ignore_asserts: bool,
|
||||
pub(crate) ip_resolve: IpResolve,
|
||||
pub(crate) insecure: bool,
|
||||
pub(crate) max_filesize: Option<u64>,
|
||||
pub(crate) max_redirect: Option<usize>,
|
||||
pub(crate) netrc: bool,
|
||||
pub(crate) netrc_file: Option<String>,
|
||||
|
Loading…
Reference in New Issue
Block a user