Skip to content

Commit

Permalink
Add a new option --header
Browse files Browse the repository at this point in the history
  • Loading branch information
theoforger committed Dec 6, 2024
1 parent 983779f commit eb88ae7
Show file tree
Hide file tree
Showing 21 changed files with 96 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,7 @@ will follow a redirection only for the second entry.
| <a href="#file-root" id="file-root"><code>--file-root &lt;DIR&gt;</code></a> | Set root directory to import files in Hurl. This is used for files in multipart form data, request body and response output.<br>When it is not explicitly defined, files are relative to the Hurl file's directory.<br><br>This is a cli-only option.<br> |
| <a href="#from-entry" id="from-entry"><code>--from-entry &lt;ENTRY_NUMBER&gt;</code></a> | Execute Hurl file from ENTRY_NUMBER (starting at 1).<br><br>This is a cli-only option.<br> |
| <a href="#glob" id="glob"><code>--glob &lt;GLOB&gt;</code></a> | Specify input files that match the given glob pattern.<br><br>Multiple glob flags may be used. This flag supports common Unix glob patterns like *, ? and [].<br>However, to avoid your shell accidentally expanding glob patterns before Hurl handles them, you must use single quotes or double quotes around each pattern.<br><br>This is a cli-only option.<br> |
| <a href="#header" id="header"><code>-H, --header &lt;HEADER&gt;</code></a> | Add an extra header to include in information sent. Can be used several times in a command<br><br>Do not add newlines or carriage returns<br><br>This is a cli-only option.<br> |
| <a href="#http10" id="http10"><code>-0, --http1.0</code></a> | Tells Hurl to use HTTP version 1.0 instead of using its internally preferred HTTP version.<br> |
| <a href="#http11" id="http11"><code>--http1.1</code></a> | Tells Hurl to use HTTP version 1.1.<br> |
| <a href="#http2" id="http2"><code>--http2</code></a> | Tells Hurl to use HTTP version 2.<br>For HTTPS, this means Hurl negotiates HTTP/2 in the TLS handshake. Hurl does this by default.<br>For HTTP, this means Hurl attempts to upgrade the request to HTTP/2 using the Upgrade: request header.<br> |
Expand Down
1 change: 1 addition & 0 deletions completions/_hurl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ _hurl() {
'--location-trusted[Follow redirects but allows sending the name + password to all hosts that the site may redirect to]' \
'--from-entry[Execute Hurl file from ENTRY_NUMBER (starting at 1)]: :' \
'*--glob[Specify input files that match the given GLOB. Multiple glob flags may be used]: :' \
'*(-H --header)'{-H,--header}'[Pass custom header(s) to server]: :' \
'(-0 --http1.0)'{-0,--http1.0}'[Tell Hurl to use HTTP version 1.0]' \
'--http1.1[Tell Hurl to use HTTP version 1.1]' \
'--http2[Tell Hurl to use HTTP version 2]' \
Expand Down
1 change: 1 addition & 0 deletions completions/_hurl.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Register-ArgumentCompleter -Native -CommandName 'hurl' -ScriptBlock {
[CompletionResult]::new('--location-trusted', 'location-trusted', [CompletionResultType]::ParameterName, 'Follow redirects but allows sending the name + password to all hosts that the site may redirect to')
[CompletionResult]::new('--from-entry', 'from-entry', [CompletionResultType]::ParameterName, 'Execute Hurl file from ENTRY_NUMBER (starting at 1)')
[CompletionResult]::new('--glob', 'glob', [CompletionResultType]::ParameterName, 'Specify input files that match the given GLOB. Multiple glob flags may be used')
[CompletionResult]::new('--header', 'header', [CompletionResultType]::ParameterName, 'Pass custom header(s) to server')
[CompletionResult]::new('--http1.0', 'http1.0', [CompletionResultType]::ParameterName, 'Tell Hurl to use HTTP version 1.0')
[CompletionResult]::new('--http1.1', 'http1.1', [CompletionResultType]::ParameterName, 'Tell Hurl to use HTTP version 1.1')
[CompletionResult]::new('--http2', 'http2', [CompletionResultType]::ParameterName, 'Tell Hurl to use HTTP version 2')
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 --curl --delay --error-format --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"))
COMPREPLY=($(compgen -W '--aws-sigv4 --cacert --cert --key --color --compressed --connect-timeout --connect-to --continue-on-error --cookie --cookie-jar --curl --delay --error-format --file-root --location --location-trusted --from-entry --glob --header --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
1 change: 1 addition & 0 deletions completions/hurl.fish
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ complete -c hurl -l location -d 'Follow redirects'
complete -c hurl -l location-trusted -d 'Follow redirects but allows sending the name + password to all hosts that the site may redirect to'
complete -c hurl -l from-entry -d 'Execute Hurl file from ENTRY_NUMBER (starting at 1)'
complete -c hurl -l glob -d 'Specify input files that match the given GLOB. Multiple glob flags may be used'
complete -c hurl -l header -d 'Pass custom header(s) to server'
complete -c hurl -l http1.0 -d 'Tell Hurl to use HTTP version 1.0'
complete -c hurl -l http1.1 -d 'Tell Hurl to use HTTP version 1.1'
complete -c hurl -l http2 -d 'Tell Hurl to use HTTP version 2'
Expand Down
1 change: 1 addition & 0 deletions docs/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ will follow a redirection only for the second entry.
| <a href="#file-root" id="file-root"><code>--file-root &lt;DIR&gt;</code></a> | Set root directory to import files in Hurl. This is used for files in multipart form data, request body and response output.<br>When it is not explicitly defined, files are relative to the Hurl file's directory.<br><br>This is a cli-only option.<br> |
| <a href="#from-entry" id="from-entry"><code>--from-entry &lt;ENTRY_NUMBER&gt;</code></a> | Execute Hurl file from ENTRY_NUMBER (starting at 1).<br><br>This is a cli-only option.<br> |
| <a href="#glob" id="glob"><code>--glob &lt;GLOB&gt;</code></a> | Specify input files that match the given glob pattern.<br><br>Multiple glob flags may be used. This flag supports common Unix glob patterns like *, ? and [].<br>However, to avoid your shell accidentally expanding glob patterns before Hurl handles them, you must use single quotes or double quotes around each pattern.<br><br>This is a cli-only option.<br> |
| <a href="#header" id="header"><code>-H, --header &lt;HEADER&gt;</code></a> | Add an extra header to include in information sent. Can be used several times in a command<br><br>Do not add newlines or carriage returns<br><br>This is a cli-only option.<br> |
| <a href="#http10" id="http10"><code>-0, --http1.0</code></a> | Tells Hurl to use HTTP version 1.0 instead of using its internally preferred HTTP version.<br> |
| <a href="#http11" id="http11"><code>--http1.1</code></a> | Tells Hurl to use HTTP version 1.1.<br> |
| <a href="#http2" id="http2"><code>--http2</code></a> | Tells Hurl to use HTTP version 2.<br>For HTTPS, this means Hurl negotiates HTTP/2 in the TLS handshake. Hurl does this by default.<br>For HTTP, this means Hurl attempts to upgrade the request to HTTP/2 using the Upgrade: request header.<br> |
Expand Down
10 changes: 9 additions & 1 deletion docs/manual/hurl.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH hurl 1 "04 Dec 2024" "hurl 6.1.0-SNAPSHOT" " Hurl Manual"
.TH hurl 1 "05 Dec 2024" "hurl 6.1.0-SNAPSHOT" " Hurl Manual"
.SH NAME

hurl - run and test HTTP requests.
Expand Down Expand Up @@ -237,6 +237,14 @@ However, to avoid your shell accidentally expanding glob patterns before Hurl ha

This is a cli-only option.

.IP "-H, --header <HEADER> "

Add an extra header to include in information sent. Can be used several times in a command

Do not add newlines or carriage returns

This is a cli-only option.

.IP "-0, --http1.0 "

Tells Hurl to use HTTP version 1.0 instead of using its internally preferred HTTP version.
Expand Down
8 changes: 8 additions & 0 deletions docs/manual/hurl.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,14 @@ However, to avoid your shell accidentally expanding glob patterns before Hurl ha

This is a cli-only option.

### -H, --header <HEADER> {#header}

Add an extra header to include in information sent. Can be used several times in a command

Do not add newlines or carriage returns

This is a cli-only option.

### -0, --http1.0 {#http10}

Tells Hurl to use HTTP version 1.0 instead of using its internally preferred HTTP version.
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 "04 Dec 2024" "hurl 6.1.0-SNAPSHOT" " Hurl Manual"
.TH hurl 1 "05 Dec 2024" "hurl 6.1.0-SNAPSHOT" " Hurl Manual"
.SH NAME

hurlfmt - format Hurl files
Expand Down
12 changes: 12 additions & 0 deletions docs/spec/options/hurl/header.option
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: header
long: header
short: H
value: HEADER
help: Pass custom header(s) to server
help_heading: HTTP options
multi: append
cli_only: true
---
Add an extra header to include in information sent. Can be used several times in a command

Do not add newlines or carriage returns
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 @@ -22,6 +22,8 @@ HTTP options:
Maximum time allowed for connection [default: 300]
--connect-to <HOST1:PORT1:HOST2:PORT2>
For a request to the given HOST1:PORT1 pair, connect to HOST2:PORT2 instead
-H, --header <HEADER>
Pass custom header(s) to server
-0, --http1.0
Tell Hurl to use HTTP version 1.0
--http1.1
Expand Down
1 change: 1 addition & 0 deletions packages/hurl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,7 @@ will follow a redirection only for the second entry.
| <a href="#file-root" id="file-root"><code>--file-root &lt;DIR&gt;</code></a> | Set root directory to import files in Hurl. This is used for files in multipart form data, request body and response output.<br>When it is not explicitly defined, files are relative to the Hurl file's directory.<br><br>This is a cli-only option.<br> |
| <a href="#from-entry" id="from-entry"><code>--from-entry &lt;ENTRY_NUMBER&gt;</code></a> | Execute Hurl file from ENTRY_NUMBER (starting at 1).<br><br>This is a cli-only option.<br> |
| <a href="#glob" id="glob"><code>--glob &lt;GLOB&gt;</code></a> | Specify input files that match the given glob pattern.<br><br>Multiple glob flags may be used. This flag supports common Unix glob patterns like *, ? and [].<br>However, to avoid your shell accidentally expanding glob patterns before Hurl handles them, you must use single quotes or double quotes around each pattern.<br><br>This is a cli-only option.<br> |
| <a href="#header" id="header"><code>-H, --header &lt;HEADER&gt;</code></a> | Add an extra header to include in information sent. Can be used several times in a command<br><br>Do not add newlines or carriage returns<br><br>This is a cli-only option.<br> |
| <a href="#http10" id="http10"><code>-0, --http1.0</code></a> | Tells Hurl to use HTTP version 1.0 instead of using its internally preferred HTTP version.<br> |
| <a href="#http11" id="http11"><code>--http1.1</code></a> | Tells Hurl to use HTTP version 1.1.<br> |
| <a href="#http2" id="http2"><code>--http2</code></a> | Tells Hurl to use HTTP version 2.<br>For HTTPS, this means Hurl negotiates HTTP/2 in the TLS handshake. Hurl does this by default.<br>For HTTP, this means Hurl attempts to upgrade the request to HTTP/2 using the Upgrade: request header.<br> |
Expand Down
11 changes: 11 additions & 0 deletions packages/hurl/src/cli/options/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,17 @@ pub fn glob() -> clap::Arg {
.action(clap::ArgAction::Append)
}

pub fn header() -> clap::Arg {
clap::Arg::new("header")
.long("header")
.short('H')
.value_name("HEADER")
.help("Pass custom header(s) to server")
.help_heading("HTTP options")
.num_args(1)
.action(clap::ArgAction::Append)
}

pub fn http10() -> clap::Arg {
clap::Arg::new("http10")
.long("http1.0")
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 @@ -155,6 +155,10 @@ pub fn from_entry(arg_matches: &ArgMatches) -> Option<usize> {
get::<u32>(arg_matches, "from_entry").map(|x| x as usize)
}

pub fn headers(arg_matches: &ArgMatches) -> Vec<String> {
get_strings(arg_matches, "header").unwrap_or_default()
}

pub fn html_dir(arg_matches: &ArgMatches) -> Result<Option<PathBuf>, CliOptionsError> {
if let Some(dir) = get::<String>(arg_matches, "report_html") {
let path = Path::new(&dir);
Expand Down
Loading

0 comments on commit eb88ae7

Please sign in to comment.