Add headers config, closes #25

This commit is contained in:
Ken-Håvard Lieng 2018-12-20 11:51:31 +01:00
parent 6aaa2b521d
commit 8526805c2f
3 changed files with 9 additions and 0 deletions

View File

@ -68,3 +68,7 @@ enabled = false
max_age = 31536000 max_age = 31536000
include_subdomains = false include_subdomains = false
preload = false preload = false
# Add your own HTTP headers to the index page
[headers]
# X-Example = "Rainbows"

View File

@ -14,6 +14,7 @@ type Config struct {
Dev bool Dev bool
HexIP bool HexIP bool
VerifyCertificates bool `mapstructure:"verify_certificates"` VerifyCertificates bool `mapstructure:"verify_certificates"`
Headers map[string]string
Defaults *Defaults Defaults *Defaults
HTTPS *HTTPS HTTPS *HTTPS
LetsEncrypt *LetsEncrypt LetsEncrypt *LetsEncrypt

View File

@ -323,6 +323,10 @@ func (d *Dispatch) serveIndex(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Strict-Transport-Security", hstsHeader) w.Header().Set("Strict-Transport-Security", hstsHeader)
} }
for k, v := range d.Config().Headers {
w.Header().Set(k, v)
}
if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") { if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") {
w.Header().Set("Content-Encoding", "gzip") w.Header().Set("Content-Encoding", "gzip")
w.Header().Set("Content-Length", indexPageLen) w.Header().Set("Content-Length", indexPageLen)