mirror of
https://github.com/grafana/grafana.git
synced 2024-11-24 09:50:29 -06:00
dd2d206d99
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
29 lines
526 B
Go
29 lines
526 B
Go
package middleware
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/grafana/grafana/pkg/models"
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
"gopkg.in/macaron.v1"
|
|
)
|
|
|
|
func ValidateHostHeader(cfg *setting.Cfg) macaron.Handler {
|
|
return func(c *models.ReqContext) {
|
|
// ignore local render calls
|
|
if c.IsRenderCall {
|
|
return
|
|
}
|
|
|
|
h := c.Req.Host
|
|
if i := strings.Index(h, ":"); i >= 0 {
|
|
h = h[:i]
|
|
}
|
|
|
|
if !strings.EqualFold(h, cfg.Domain) {
|
|
c.Redirect(strings.TrimSuffix(cfg.AppURL, "/")+c.Req.RequestURI, 301)
|
|
return
|
|
}
|
|
}
|
|
}
|