refactor: remove duplicate IsHTTPS, use middleware.IsHTTPS

This commit is contained in:
2025-12-26 17:40:47 +01:00
parent 9017816812
commit ab3efc99a8

View File

@@ -93,7 +93,7 @@ func SetVoteCookie(w http.ResponseWriter, r *http.Request, postID uint, voteType
Path: "/",
MaxAge: SecondsPerDay * CookieMaxAgeDays,
HttpOnly: true,
Secure: IsHTTPS(r),
Secure: middleware.IsHTTPS(r),
SameSite: http.SameSiteLaxMode,
}
@@ -121,26 +121,6 @@ func ClearVoteCookie(w http.ResponseWriter, postID uint) {
http.SetCookie(w, cookie)
}
func IsHTTPS(r *http.Request) bool {
if r.TLS != nil {
return true
}
if proto := r.Header.Get("X-Forwarded-Proto"); proto == "https" {
return true
}
if proto := r.Header.Get("X-Forwarded-Ssl"); proto == "on" {
return true
}
if proto := r.Header.Get("X-Forwarded-Scheme"); proto == "https" {
return true
}
return false
}
func SanitizeUser(user *database.User) dto.SanitizedUserDTO {
if user == nil {
return dto.SanitizedUserDTO{}