2015-05-05 04:21:06 -05:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
2016-01-13 08:43:32 -06:00
|
|
|
"gopkg.in/macaron.v1"
|
2015-05-05 04:21:06 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func ValidateHostHeader(domain string) macaron.Handler {
|
2016-12-05 04:20:01 -06:00
|
|
|
return func(c *Context) {
|
|
|
|
// ignore local render calls
|
|
|
|
if c.IsRenderCall {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-05-05 04:21:06 -05:00
|
|
|
h := c.Req.Host
|
|
|
|
if i := strings.Index(h, ":"); i >= 0 {
|
|
|
|
h = h[:i]
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.EqualFold(h, domain) {
|
|
|
|
c.Redirect(strings.TrimSuffix(setting.AppUrl, "/")+c.Req.RequestURI, 301)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|