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

Add a handler to every route adding response header #10

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,12 @@ and providing cert and key files at the specified location. This is mostly for
dev and testing setups and is not useful for a public domain as the cert is not
issued by a trusted CA and therefore not trusted by browsers. If set, this
overrules `ENABLE_AUTO_HTTPS`.

## HSTS (HTTP Strict-Transport-Security)

Set `HSTS=<header_value>` in order to add the HTTP header

Strict-Transport-Security: <header_value>

to every response. See [mozilla's documentation](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security)
for more details.
2 changes: 1 addition & 1 deletion caddy_base.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@
{
"handle": [
{
"handler": "static_response",
"body": "Misdirected Request",
"close": true,
"handler": "static_response",
"status_code": 421
}
],
Expand Down
6 changes: 6 additions & 0 deletions entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,10 @@ else
jq_write "del(.apps.http.servers.srv0.routes[-2])"
fi

### Strict-Transport-Security ###
if [ -n "$HSTS" ]; then
handler="{ \"handler\": \"headers\", \"response\": { \"add\": { \"Strict-Transport-Security\": [ \"${HSTS}\" ] } } }"
jq_write ".apps.http.servers.srv0.routes[].handle |= [ ${handler} ] + ."
fi

exec "$@"