优化结构

This commit is contained in:
Yvan
2026-08-20 23:02:06 +08:00
parent 63dbb4cfbc
commit e65cf0b1d0
338 changed files with 622 additions and 481 deletions
-27
View File
@@ -1,27 +0,0 @@
package httpx
import (
"net/http"
"strings"
"time"
"github.com/gin-gonic/gin"
)
func requestUsesHTTPS(request *http.Request) bool {
if request.TLS != nil {
return true
}
forwarded := strings.SplitN(request.Header.Get("X-Forwarded-Proto"), ",", 2)[0]
return strings.EqualFold(strings.TrimSpace(forwarded), "https")
}
// SetTokenCookie also marks cookies Secure behind TLS or a TLS-terminating
// reverse proxy.
func SetTokenCookie(c *gin.Context, value string, maxAge int) {
cookie := &http.Cookie{Name: "x-token", Value: value, Path: "/", MaxAge: maxAge, Secure: requestUsesHTTPS(c.Request), HttpOnly: true, SameSite: http.SameSiteStrictMode}
if maxAge < 0 {
cookie.Expires = time.Unix(1, 0)
}
http.SetCookie(c.Writer, cookie)
}