func ProxyAlertDataSourceRequest(c *middleware.Context) { targetUrl, _ := url.Parse(setting.Alert.AlertUrlRoot) director := func(req *http.Request) { req.URL.Scheme = targetUrl.Scheme req.URL.Host = targetUrl.Host req.Host = targetUrl.Host reqQueryVals := req.URL.Query() reqQueryVals.Add("org", strconv.FormatInt(c.OrgId, 10)) req.URL.RawQuery = reqQueryVals.Encode() req.URL.Path = util.JoinUrlFragments(targetUrl.Path, "/healthsummary") // clear cookie headers req.Header.Del("Cookie") req.Header.Del("Set-Cookie") } proxy := &httputil.ReverseProxy{Director: director} proxy.Transport = dataProxyTransport proxy.ServeHTTP(c.RW(), c.Req.Request) }
func ProxyDataSourceRequest(c *middleware.Context) { ds, err := getDatasource(c.ParamsInt64(":id"), c.OrgId) if err != nil { c.JsonApiErr(500, "Unable to load datasource meta data", err) return } targetUrl, _ := url.Parse(ds.Url) if len(setting.DataProxyWhiteList) > 0 { if _, exists := setting.DataProxyWhiteList[targetUrl.Host]; !exists { c.JsonApiErr(403, "Data proxy hostname and ip are not included in whitelist", nil) return } } if ds.Type == m.DS_CLOUDWATCH { cloudwatch.HandleRequest(c, ds) } else { proxyPath := c.Params("*") proxy := NewReverseProxy(ds, proxyPath, targetUrl) proxy.Transport = dataProxyTransport proxy.ServeHTTP(c.RW(), c.Req.Request) } }