Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve documentation for the --header parameter #1389

Merged
merged 12 commits into from
Apr 26, 2024
Merged
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,22 @@ Sometimes this is just a more practical and quick way than doing things properly

miniserve -i 192.168.0.1 -i 10.13.37.10 -i ::1 /tmp/myshare

### Insert custom headers

miniserve --header "Cache-Control:no-cache" --header "X-Custom-Header:custom-value" -p 8080 /tmp/myshare
# Check headers in another terminal
curl -I http://localhost:8080

If a header is already set or previously inserted, it will not be overwritten.

### Start with TLS:

miniserve --tls-cert my.cert --tls-key my.key /tmp/myshare
# Fullchain TLS and HTTP Strict Transport Security (HSTS)
miniserve --tls-cert fullchain.pem --tls-key my.key --header "Strict-Transport-Security: max-age=31536000; includeSubDomains; preload" /tmp/myshare

If the parameter value has spaces, be sure to wrap it in quotes.
(To achieve an A+ rating at https://www.ssllabs.com/ssltest/, enabling both fullchain TLS and HSTS is necessary.)

### Upload a file using `curl`:

Expand Down Expand Up @@ -314,7 +327,12 @@ Options:
[env: MINISERVE_TITLE=]

--header <HEADER>
Set custom header for responses
Inserts custom headers into the responses. Specify each header as a 'Header:Value' pair.
This parameter can be used multiple times to add multiple headers.

Example:
--header "Header1:Value1" --header "Header2:Value2"
(If a header is already set or previously inserted, it will not be overwritten.)

[env: MINISERVE_HEADER=]

Expand Down
7 changes: 6 additions & 1 deletion src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,12 @@ pub struct CliArgs {
#[arg(short = 't', long = "title", env = "MINISERVE_TITLE")]
pub title: Option<String>,

/// Set custom header for responses
/// Inserts custom headers into the responses. Specify each header as a 'Header:Value' pair.
/// This parameter can be used multiple times to add multiple headers.
orwithout marked this conversation as resolved.
Show resolved Hide resolved
///
/// Example:
/// --header "Header1:Value1" --header "Header2:Value2"
/// (If a header is already set or previously inserted, it will not be overwritten.)
#[arg(
long = "header",
value_parser(parse_header),
Expand Down
Loading