20 lines
482 B
Go
20 lines
482 B
Go
package middleware
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
// TrustProxy восстанавливает схему HTTPS за Caddy/nginx.
|
|
func TrustProxy(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if proto := r.Header.Get("X-Forwarded-Proto"); strings.EqualFold(proto, "https") {
|
|
r.URL.Scheme = "https"
|
|
}
|
|
if host := r.Header.Get("X-Forwarded-Host"); host != "" {
|
|
r.Host = host
|
|
}
|
|
next.ServeHTTP(w, r)
|
|
})
|
|
}
|