| 
									
										
										
										
											2015-05-05 17:21:06 +08:00
										 |  |  | package middleware | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"strings" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/grafana/grafana/pkg/setting" | 
					
						
							| 
									
										
										
										
											2016-01-13 22:43:32 +08:00
										 |  |  | 	"gopkg.in/macaron.v1" | 
					
						
							| 
									
										
										
										
											2015-05-05 17:21:06 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func ValidateHostHeader(domain string) macaron.Handler { | 
					
						
							|  |  |  | 	return func(c *macaron.Context) { | 
					
						
							|  |  |  | 		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 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |