代码拉取完成,页面将自动刷新
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"
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。