Skip to content

Commit

Permalink
Implement --limit-rate from curl
Browse files Browse the repository at this point in the history
  • Loading branch information
jcamiel committed Oct 25, 2024
1 parent f1a35a0 commit 8633a31
Show file tree
Hide file tree
Showing 27 changed files with 167 additions and 28 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1247,9 +1247,10 @@ will follow a redirection only for the second entry.
| <a href="#jobs" id="jobs"><code>--jobs &lt;NUM&gt;</code></a> | Maximum number of parallel jobs in parallel mode. Default value corresponds (in most cases) to the<br>current amount of CPUs.<br><br>See also [`--parallel`](#parallel).<br><br>This is a cli-only option.<br> |
| <a href="#json" id="json"><code>--json</code></a> | Output each Hurl file result to JSON. The format is very closed to HAR format.<br><br>This is a cli-only option.<br> |
| <a href="#key" id="key"><code>--key &lt;KEY&gt;</code></a> | Private key file name.<br> |
| <a href="#limit-rate" id="limit-rate"><code>--limit-rate &lt;SPEED&gt;</code></a> | Specify the maximum transfer rate you want Hurl to use, for both downloads and uploads. This feature is useful if you have a limited pipe and you would like your transfer not to use your entire bandwidth. To make it slower than it otherwise would be.<br>The given speed is measured in bytes/second.<br><br>This is a cli-only option.<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><br>This is a cli-only option.<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><br>This is a cli-only option.<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>You can specify time units in the maximum time expression. Set Hurl to use a maximum time of 20 seconds with `--max-time 20s` or set it to 35,000 milliseconds with `--max-time 35000ms`. No spaces allowed.<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
3 changes: 2 additions & 1 deletion completions/_hurl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ _hurl() {
'(-6 --ipv6)'{-6,--ipv6}'[Tell Hurl to use IPv6 addresses only when resolving host names, and not for example try IPv4]' \
'--jobs[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]: :' \
'--limit-rate[Specify the maximum transfer rate in bytes/second, for both downloads and uploads]: :' \
'--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
3 changes: 2 additions & 1 deletion completions/_hurl.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ 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, '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('--limit-rate', 'limit-rate', [CompletionResultType]::ParameterName, 'Specify the maximum transfer rate in bytes/second, for both downloads and uploads')
[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-filesize --max-redirs --max-time --netrc --netrc-file --netrc-optional --no-color --no-output --noproxy --output --parallel --path-as-is --proxy --repeat --report-html --report-json --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 --limit-rate --max-filesize --max-redirs --max-time --netrc --netrc-file --netrc-optional --no-color --no-output --noproxy --output --parallel --path-as-is --proxy --repeat --report-html --report-json --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
3 changes: 2 additions & 1 deletion completions/hurl.fish
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ 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 '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 limit-rate -d 'Specify the maximum transfer rate in bytes/second, for both downloads and uploads'
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
3 changes: 2 additions & 1 deletion docs/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,10 @@ will follow a redirection only for the second entry.
| <a href="#jobs" id="jobs"><code>--jobs &lt;NUM&gt;</code></a> | Maximum number of parallel jobs in parallel mode. Default value corresponds (in most cases) to the<br>current amount of CPUs.<br><br>See also [`--parallel`](#parallel).<br><br>This is a cli-only option.<br> |
| <a href="#json" id="json"><code>--json</code></a> | Output each Hurl file result to JSON. The format is very closed to HAR format.<br><br>This is a cli-only option.<br> |
| <a href="#key" id="key"><code>--key &lt;KEY&gt;</code></a> | Private key file name.<br> |
| <a href="#limit-rate" id="limit-rate"><code>--limit-rate &lt;SPEED&gt;</code></a> | Specify the maximum transfer rate you want Hurl to use, for both downloads and uploads. This feature is useful if you have a limited pipe and you would like your transfer not to use your entire bandwidth. To make it slower than it otherwise would be.<br>The given speed is measured in bytes/second.<br><br>This is a cli-only option.<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><br>This is a cli-only option.<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><br>This is a cli-only option.<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>You can specify time units in the maximum time expression. Set Hurl to use a maximum time of 20 seconds with `--max-time 20s` or set it to 35,000 milliseconds with `--max-time 35000ms`. No spaces allowed.<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
11 changes: 9 additions & 2 deletions docs/manual/hurl.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH hurl 1 "24 Oct 2024" "hurl 6.0.0-SNAPSHOT" " Hurl Manual"
.TH hurl 1 "25 Oct 2024" "hurl 6.0.0-SNAPSHOT" " Hurl Manual"
.SH NAME

hurl - run and test HTTP requests.
Expand Down Expand Up @@ -300,6 +300,13 @@ This is a cli-only option.

Private key file name.

.IP "--limit-rate <SPEED> "

Specify the maximum transfer rate you want Hurl to use, for both downloads and uploads. This feature is useful if you have a limited pipe and you would like your transfer not to use your entire bandwidth. To make it slower than it otherwise would be.
The given speed is measured in bytes/second.

This is a cli-only option.

.IP "-L, --location "

Follow redirect. To limit the amount of redirects to follow use the \fI--max-redirs\fP option
Expand All @@ -311,7 +318,7 @@ This may or may not introduce a security breach if the site redirects you to a s

.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.
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.

This is a cli-only option.

Expand Down
9 changes: 8 additions & 1 deletion docs/manual/hurl.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,13 @@ This is a cli-only option.

Private key file name.

### --limit-rate <SPEED> {#limit-rate}

Specify the maximum transfer rate you want Hurl to use, for both downloads and uploads. This feature is useful if you have a limited pipe and you would like your transfer not to use your entire bandwidth. To make it slower than it otherwise would be.
The given speed is measured in bytes/second.

This is a cli-only option.

### -L, --location {#location}

Follow redirect. To limit the amount of redirects to follow use the [`--max-redirs`](#max-redirs) option
Expand All @@ -330,7 +337,7 @@ This may or may not introduce a security breach if the site redirects you to a s

### --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.
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.

This is a cli-only option.

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 "24 Oct 2024" "hurl 6.0.0-SNAPSHOT" " Hurl Manual"
.TH hurl 1 "25 Oct 2024" "hurl 6.0.0-SNAPSHOT" " Hurl Manual"
.SH NAME

hurlfmt - format Hurl files
Expand Down
10 changes: 10 additions & 0 deletions docs/spec/options/hurl/limit_rate.option
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: limit_rate
long: limit-rate
value: SPEED
value_parser: clap::value_parser!(u64)
help: Specify the maximum transfer rate in bytes/second, for both downloads and uploads
help_heading: HTTP options
cli_only: true
---
Specify the maximum transfer rate you want Hurl to use, for both downloads and uploads. This feature is useful if you have a limited pipe and you would like your transfer not to use your entire bandwidth. To make it slower than it otherwise would be.
The given speed is measured in bytes/second.
Loading

0 comments on commit 8633a31

Please sign in to comment.