mirror of
https://github.com/komari-monitor/komari.git
synced 2025-11-04 22:13:19 +00:00
32 lines
874 B
Go
32 lines
874 B
Go
package utils
|
|
|
|
import "github.com/gin-gonic/gin"
|
|
|
|
// https://github.com/labstack/echo/blob/98ca08e7dd64075b858e758d6693bf9799340756/context.go#L275-L294
|
|
func GetScheme(c *gin.Context) string {
|
|
// Can't use `r.Request.URL.Scheme`
|
|
// See: https://groups.google.com/forum/#!topic/golang-nuts/pMUkBlQBDF0
|
|
if c.Request.TLS != nil {
|
|
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"
|
|
}
|
|
|
|
func GetCallbackURL(c *gin.Context) string {
|
|
scheme := GetScheme(c)
|
|
host := c.Request.Host
|
|
return scheme + "://" + host + "/api/oauth_callback"
|
|
}
|