1 Star 0 Fork 0

carlmax_my/console-core-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
gin.go 981 Bytes
一键复制 编辑 原始数据 按行查看 历史
carlmax_my 提交于 2024-12-02 21:32 . init project
package util
import "github.com/gin-gonic/gin"
func IsSSL(c *gin.Context) bool {
return c.Request.TLS != nil
}
func IsHttps(c *gin.Context) bool {
return GetRequestScheme(c) == "https"
}
func IsHttp(c *gin.Context) bool {
return GetRequestScheme(c) == "http"
}
func GetUserAgent(c *gin.Context) string {
return c.GetHeader("User-Agent")
}
// websocket TODO
// Upgrade: websocket Connection: ...Upgrade...
func GetRequestScheme(c *gin.Context) string {
// Can't use `r.Request.URL.Scheme`
// See: https://groups.google.com/forum/#!topic/golang-nuts/pMUkBlQBDF0
if IsSSL(c) {
return "https"
}
if scheme := c.Request.Header.Get("X-Forwarded-Proto"); scheme != "" {
return scheme
}
if scheme := c.Request.Header.Get("X-Forwarded-Protocol"); scheme != "" {
return scheme
}
if ssl := c.Request.Header.Get("X-Forwarded-Ssl"); ssl == "on" {
return "https"
}
if scheme := c.Request.Header.Get("X-Url-Scheme"); scheme != "" {
return scheme
}
return "http"
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/carlmax_my/console-core-go.git
git@gitee.com:carlmax_my/console-core-go.git
carlmax_my
console-core-go
console-core-go
v0.0.20

搜索帮助

0d507c66 1850385 C8b1a773 1850385