mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-10-22 02:35:22 +00:00
improvements to middleware and URL resolver
This commit is contained in:
@@ -7,9 +7,9 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// Hostname is a middleware function that evaluates the http.Request
|
||||
// and adds the real hostname and scheme to the context.
|
||||
func Hostname(c *gin.Context) {
|
||||
// Resolve is a middleware function that resolves the hostname
|
||||
// and scheme for the http.Request and adds to the context.
|
||||
func Resolve(c *gin.Context) {
|
||||
c.Set("host", resolveHost(c.Request))
|
||||
c.Set("scheme", resolveScheme(c.Request))
|
||||
c.Next()
|
||||
@@ -56,3 +56,13 @@ func resolveHost(r *http.Request) string {
|
||||
return "localhost:8000"
|
||||
}
|
||||
}
|
||||
|
||||
// Hostname returns the hostname associated with
|
||||
// the current context.
|
||||
func Hostname(c *gin.Context) (host string) {
|
||||
v, ok := c.Get("host")
|
||||
if ok {
|
||||
host = v.(string)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user