mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Plugin proxy: Handle URL parsing errors (#29093)
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
@@ -57,7 +57,12 @@ func AppPluginRoute(route *plugins.AppPluginRoute, appID string, hs *HTTPServer)
|
|||||||
return func(c *models.ReqContext) {
|
return func(c *models.ReqContext) {
|
||||||
path := c.Params("*")
|
path := c.Params("*")
|
||||||
|
|
||||||
proxy := pluginproxy.NewApiPluginProxy(c, path, route, appID, hs.Cfg)
|
proxy, err := pluginproxy.NewApiPluginProxy(c, path, route, appID, hs.Cfg)
|
||||||
|
if err != nil {
|
||||||
|
c.JsonApiErr(500, "Failed to create API plugin proxy", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
proxy.Transport = pluginProxyTransport
|
proxy.Transport = pluginProxyTransport
|
||||||
proxy.ServeHTTP(c.Resp, c.Req.Request)
|
proxy.ServeHTTP(c.Resp, c.Req.Request)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,8 +56,12 @@ func updateURL(route *plugins.AppPluginRoute, orgId int64, appID string) (string
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewApiPluginProxy create a plugin proxy
|
// NewApiPluginProxy create a plugin proxy
|
||||||
func NewApiPluginProxy(ctx *models.ReqContext, proxyPath string, route *plugins.AppPluginRoute, appID string, cfg *setting.Cfg) *httputil.ReverseProxy {
|
func NewApiPluginProxy(ctx *models.ReqContext, proxyPath string, route *plugins.AppPluginRoute, appID string,
|
||||||
targetURL, _ := url.Parse(route.URL)
|
cfg *setting.Cfg) (*httputil.ReverseProxy, error) {
|
||||||
|
targetURL, err := url.Parse(route.URL)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
director := func(req *http.Request) {
|
director := func(req *http.Request) {
|
||||||
req.URL.Scheme = targetURL.Scheme
|
req.URL.Scheme = targetURL.Scheme
|
||||||
@@ -115,5 +119,5 @@ func NewApiPluginProxy(ctx *models.ReqContext, proxyPath string, route *plugins.
|
|||||||
// log.Tracef("Proxying plugin request: %s", string(reqBytes))
|
// log.Tracef("Proxying plugin request: %s", string(reqBytes))
|
||||||
}
|
}
|
||||||
|
|
||||||
return &httputil.ReverseProxy{Director: director}
|
return &httputil.ReverseProxy{Director: director}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,7 +140,8 @@ func getPluginProxiedRequest(ctx *models.ReqContext, cfg *setting.Cfg, route *pl
|
|||||||
ReqRole: models.ROLE_EDITOR,
|
ReqRole: models.ROLE_EDITOR,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
proxy := NewApiPluginProxy(ctx, "", route, "", cfg)
|
proxy, err := NewApiPluginProxy(ctx, "", route, "", cfg)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
req, err := http.NewRequest(http.MethodGet, route.URL, nil)
|
req, err := http.NewRequest(http.MethodGet, route.URL, nil)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|||||||
Reference in New Issue
Block a user