aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authororwithout <he.haifeng@hotmail.com>2024-04-26 10:00:23 +0000
committerGitHub <noreply@github.com>2024-04-26 10:00:23 +0000
commitc85d9e316fc8e3cc1505126014690537ca2637ec (patch)
tree0e3a674d82816045365e3b7e941cf44ed3ef3a35
parentBump deps (diff)
downloadminiserve-c85d9e316fc8e3cc1505126014690537ca2637ec.tar.gz
miniserve-c85d9e316fc8e3cc1505126014690537ca2637ec.zip
Improve documentation for the --header parameter (#1389)
* Improve documentation for the --header parameter * Add Support for HSTS to Enhance HTTPS Security --------- Co-authored-by: orwithout <googoldecibel@gmail.com>
-rw-r--r--README.md20
-rw-r--r--src/args.rs7
2 files changed, 25 insertions, 2 deletions
diff --git a/README.md b/README.md
index e9e7ef0..bff3de7 100644
--- a/README.md
+++ b/README.md
@@ -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`:
@@ -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=]
diff --git a/src/args.rs b/src/args.rs
index 3fb0ede..95c8bff 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -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.
+ ///
+ /// 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),