4
0

header_config.go 674 B

123456789101112131415161718192021222324
  1. // Copyright 2018 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package middleware // import "miniflux.app/middleware"
  5. import (
  6. "net/http"
  7. )
  8. // HeaderConfig changes config values according to HTTP headers.
  9. func (m *Middleware) HeaderConfig(next http.Handler) http.Handler {
  10. return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  11. if r.Header.Get("X-Forwarded-Proto") == "https" {
  12. m.cfg.IsHTTPS = true
  13. }
  14. if m.cfg.IsHTTPS && m.cfg.HasHSTS() {
  15. w.Header().Set("Strict-Transport-Security", "max-age=31536000")
  16. }
  17. next.ServeHTTP(w, r)
  18. })
  19. }