Skip to content

Commit

Permalink
feat: File size limits
Browse files Browse the repository at this point in the history
  • Loading branch information
baerwang authored and jcamiel committed Apr 1, 2024
1 parent 7296757 commit 7787d71
Show file tree
Hide file tree
Showing 19 changed files with 69 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,7 @@ will follow a redirection only for the second entry.
| <a href="#key" id="key"><code>--key &lt;KEY&gt;</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 &lt;BYTES&gt;</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 &lt;NUM&gt;</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 &lt;SECONDS&gt;</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> |
Expand Down
1 change: 1 addition & 0 deletions completions/_hurl
Original file line number Diff line number Diff line change
Expand Up @@ -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]' \
Expand Down
1 change: 1 addition & 0 deletions completions/_hurl.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion completions/hurl.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions completions/hurl.fish
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions docs/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ will follow a redirection only for the second entry.
| <a href="#key" id="key"><code>--key &lt;KEY&gt;</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 &lt;BYTES&gt;</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 &lt;NUM&gt;</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 &lt;SECONDS&gt;</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> |
Expand Down
6 changes: 5 additions & 1 deletion docs/manual/hurl.1
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions docs/manual/hurl.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/manual/hurlfmt.1
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 7 additions & 0 deletions docs/spec/options/hurl/max_filesize.option
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 2 additions & 0 deletions integration/hurl/tests_ok/help.out.pattern
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions packages/hurl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,7 @@ will follow a redirection only for the second entry.
| <a href="#key" id="key"><code>--key &lt;KEY&gt;</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 &lt;BYTES&gt;</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 &lt;NUM&gt;</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 &lt;SECONDS&gt;</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> |
Expand Down
9 changes: 9 additions & 0 deletions packages/hurl/src/cli/options/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 4 additions & 0 deletions packages/hurl/src/cli/options/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![];
Expand Down
Loading

0 comments on commit 7787d71

Please sign in to comment.