package middleware import ( "strings" "github.com/gin-gonic/gin" ) // IsHTTPSRequest reports whether the client reached us over TLS. Behind a // reverse proxy (Caddy/nginx) the app itself usually terminates plain // connections, so X-Forwarded-Proto is consulted as well. The header is only // honored when a trusted proxy forwarded the request - untrusted clients // spoofing it can at worst break their own session (the cookie turns Secure // and is refused over plain HTTP). func IsHTTPSRequest(c *gin.Context) bool { if c.Request.TLS != nil { return true } if strings.EqualFold(c.GetHeader("X-Forwarded-Proto"), "https") { return true } return false }