Skip to content

Commit

Permalink
Add header option per request
Browse files Browse the repository at this point in the history
* Remove `cli-only`
* Add `header` in the `options` field
* Add integration test for header option
  • Loading branch information
theoforger committed Jan 11, 2025
1 parent e7f9708 commit 9349ff3
Show file tree
Hide file tree
Showing 25 changed files with 82 additions and 32 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +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="#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> |
| <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
42 changes: 22 additions & 20 deletions docs/grammar.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +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="#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> |
| <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
4 changes: 1 addition & 3 deletions docs/manual/hurl.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH hurl 1 "16 Dec 2024" "hurl 6.1.0-SNAPSHOT" " Hurl Manual"
.TH hurl 1 "19 Dec 2024" "hurl 6.1.0-SNAPSHOT" " Hurl Manual"
.SH NAME

hurl - run and test HTTP requests.
Expand Down Expand Up @@ -243,8 +243,6 @@ Add an extra header to include in information sent. Can be used several times in

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
2 changes: 0 additions & 2 deletions docs/manual/hurl.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,6 @@ Add an extra header to include in information sent. Can be used several times in

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 "16 Dec 2024" "hurl 6.1.0-SNAPSHOT" " Hurl Manual"
.TH hurl 1 "19 Dec 2024" "hurl 6.1.0-SNAPSHOT" " Hurl Manual"
.SH NAME

hurlfmt - format Hurl files
Expand Down
3 changes: 3 additions & 0 deletions docs/spec/grammar/hurl.grammar
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ option:
| delay-option
| follow-redirect-option
| follow-redirect-trusted-option
| header-option
| http10-option
| http11-option
| http2-option
Expand Down Expand Up @@ -173,6 +174,8 @@ follow-redirect-option: "location" ":" boolean-option lt

follow-redirect-trusted-option: "location-trusted" ":" boolean-option lt

header-option: "header" ":" value-string lt

http10-option: "http1.0" ":" boolean-option lt

http11-option: "http1.1" ":" boolean-option lt
Expand Down
1 change: 0 additions & 1 deletion docs/spec/options/hurl/header.option
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ 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

Expand Down
2 changes: 1 addition & 1 deletion integration/hurl/tests_error_parser/invalid_option.err
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ error: Parsing option
--> tests_error_parser/invalid_option.hurl:3:1
|
3 | foo: true
| ^ the option name is not valid. Valid values are aws-sigv4, cacert, cert, compressed, connect-to, delay, insecure, http1.0, http1.1, http2, http3, ipv4, ipv6, key, location, max-redirs, output, path-as-is, proxy, resolve, retry, retry-interval, skip, unix-socket, variable, verbose, very-verbose
| ^ the option name is not valid. Valid values are aws-sigv4, cacert, cert, compressed, connect-to, delay, insecure, header, http1.0, http1.1, http2, http3, ipv4, ipv6, key, location, max-redirs, output, path-as-is, proxy, resolve, retry, retry-interval, skip, unix-socket, variable, verbose, very-verbose
|

7 changes: 7 additions & 0 deletions integration/hurl/tests_ok/header_option.hurl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
GET http://localhost:8000/header-option
test: from-header-syntax
[Options]
header: test: from-option-1
header: test: from-option-2
header: another-test: from-option
HTTP 200
4 changes: 4 additions & 0 deletions integration/hurl/tests_ok/header_option.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Set-StrictMode -Version latest
$ErrorActionPreference = 'Stop'

hurl tests_ok/header_option.hurl --header 'test: from-cli'
12 changes: 12 additions & 0 deletions integration/hurl/tests_ok/header_option.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from app import app
from flask import request


@app.route("/header-option")
def header_option():
assert (
request.headers.get("test")
== "from-header-syntax,from-cli,from-option-1,from-option-2"
)
assert request.headers.get("another-test") == "from-option"
return ""
4 changes: 4 additions & 0 deletions integration/hurl/tests_ok/header_option.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
set -Eeuo pipefail

hurl tests_ok/header_option.hurl --header 'test: from-cli'
2 changes: 2 additions & 0 deletions integration/hurlfmt/tests_export/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<span class="line"><span class="string">delay</span>: <span class="number">1</span><span class="unit">s</span></span>
<span class="line"><span class="string">location</span>: <span class="boolean">false</span></span>
<span class="line"><span class="string">location-trusted</span>: <span class="boolean">false</span></span>
<span class="line"><span class="string">header</span>: <span class="string">key: value</span></span>
<span class="line"><span class="string">http1.0</span>: <span class="boolean">false</span></span>
<span class="line"><span class="string">http1.1</span>: <span class="boolean">false</span></span>
<span class="line"><span class="string">http2</span>: <span class="boolean">false</span></span>
Expand Down Expand Up @@ -61,6 +62,7 @@
<span class="line"><span class="string">delay</span>: <span class="expr">{{delay}}</span></span>
<span class="line"><span class="string">location</span>: <span class="expr">{{location}}</span></span>
<span class="line"><span class="string">location-trusted</span>: <span class="expr">{{location-trusted}}</span></span>
<span class="line"><span class="string">header</span>: <span class="string">{{header}}</span></span>
<span class="line"><span class="string">http1.0</span>: <span class="expr">{{http10}}</span></span>
<span class="line"><span class="string">http1.1</span>: <span class="expr">{{http11}}</span></span>
<span class="line"><span class="string">http2</span>: <span class="expr">{{http2}}</span></span>
Expand Down
2 changes: 2 additions & 0 deletions integration/hurlfmt/tests_export/options.hurl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ delay: 1000ms
delay: 1s
location: false
location-trusted: false
header: key: value
http1.0: false
http1.1: false
http2: false
Expand Down Expand Up @@ -61,6 +62,7 @@ connect-timeout: {{connect-timeout}}
delay: {{delay}}
location: {{location}}
location-trusted: {{location-trusted}}
header: {{header}}
http1.0: {{http10}}
http1.1: {{http11}}
http2: {{http2}}
Expand Down
Loading

0 comments on commit 9349ff3

Please sign in to comment.