improvements to middleware and URL resolver
This commit is contained in:
parent
eb04d418d9
commit
af2ef2347a
3 changed files with 15 additions and 4 deletions
1
cache/cache_test.go
vendored
1
cache/cache_test.go
vendored
|
@ -3,7 +3,6 @@ package cache
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
// "github.com/drone/drone/model"
|
|
||||||
"github.com/franela/goblin"
|
"github.com/franela/goblin"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
|
@ -7,9 +7,9 @@ import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Hostname is a middleware function that evaluates the http.Request
|
// Resolve is a middleware function that resolves the hostname
|
||||||
// and adds the real hostname and scheme to the context.
|
// and scheme for the http.Request and adds to the context.
|
||||||
func Hostname(c *gin.Context) {
|
func Resolve(c *gin.Context) {
|
||||||
c.Set("host", resolveHost(c.Request))
|
c.Set("host", resolveHost(c.Request))
|
||||||
c.Set("scheme", resolveScheme(c.Request))
|
c.Set("scheme", resolveScheme(c.Request))
|
||||||
c.Next()
|
c.Next()
|
||||||
|
@ -56,3 +56,13 @@ func resolveHost(r *http.Request) string {
|
||||||
return "localhost:8000"
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"github.com/drone/drone/controller"
|
"github.com/drone/drone/controller"
|
||||||
"github.com/drone/drone/router/middleware/cache"
|
"github.com/drone/drone/router/middleware/cache"
|
||||||
"github.com/drone/drone/router/middleware/header"
|
"github.com/drone/drone/router/middleware/header"
|
||||||
|
"github.com/drone/drone/router/middleware/location"
|
||||||
"github.com/drone/drone/router/middleware/session"
|
"github.com/drone/drone/router/middleware/session"
|
||||||
"github.com/drone/drone/router/middleware/token"
|
"github.com/drone/drone/router/middleware/token"
|
||||||
"github.com/drone/drone/static"
|
"github.com/drone/drone/static"
|
||||||
|
@ -20,6 +21,7 @@ func Load(middleware ...gin.HandlerFunc) http.Handler {
|
||||||
e.SetHTMLTemplate(template.Load())
|
e.SetHTMLTemplate(template.Load())
|
||||||
e.StaticFS("/static", static.FileSystem())
|
e.StaticFS("/static", static.FileSystem())
|
||||||
|
|
||||||
|
e.Use(location.Resolve)
|
||||||
e.Use(header.NoCache)
|
e.Use(header.NoCache)
|
||||||
e.Use(header.Options)
|
e.Use(header.Options)
|
||||||
e.Use(header.Secure)
|
e.Use(header.Secure)
|
||||||
|
|
Loading…
Reference in a new issue