header_config.go 525 B

12345678910111213141516171819
  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
  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. next.ServeHTTP(w, r)
  15. })
  16. }