Add HSTS header

This commit is contained in:
Melon 2023-11-03 08:09:29 +00:00
parent 1194717a32
commit 37b0617e78
Signed by: melon
GPG Key ID: 6C9D970C50D26A25

View File

@ -26,8 +26,11 @@ func NewHttpsServer(conf *conf.Conf) *http.Server {
rateLimiter := setupRateLimiter(conf.RateLimit, favMiddleware) rateLimiter := setupRateLimiter(conf.RateLimit, favMiddleware)
return &http.Server{ return &http.Server{
Addr: conf.HttpsListen, Addr: conf.HttpsListen,
Handler: rateLimiter, Handler: http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
rw.Header().Set("Strict-Transport-Security", "max-age=63072000; includeSubDomains")
rateLimiter.ServeHTTP(rw, req)
}),
TLSConfig: &tls.Config{GetCertificate: func(info *tls.ClientHelloInfo) (*tls.Certificate, error) { TLSConfig: &tls.Config{GetCertificate: func(info *tls.ClientHelloInfo) (*tls.Certificate, error) {
// error out on invalid domains // error out on invalid domains
if !conf.Domains.IsValid(info.ServerName) { if !conf.Domains.IsValid(info.ServerName) {