mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
dataproxy should forward a trailing slash to proxy
This commit is contained in:
parent
8bf4d68035
commit
3fa8088192
@ -51,17 +51,21 @@ func (hs *HTTPServer) ProxyDataSourceRequest(c *m.ReqContext) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
proxyPath := c.Params("*")
|
|
||||||
|
|
||||||
// Check for a trailing slash, and pass it to the proxy
|
|
||||||
// macaron does not include trailing slashes when resolving a wildcard path
|
// macaron does not include trailing slashes when resolving a wildcard path
|
||||||
if len(proxyPath) > 1 {
|
proxyPath := ensureProxyPathTrailingSlash(c.Req.URL.Path, c.Params("*"))
|
||||||
path := c.Req.URL.Path
|
|
||||||
if path[len(path)-1] == '/' && proxyPath[len(proxyPath)-1] != '/' {
|
|
||||||
proxyPath += "/"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
proxy := pluginproxy.NewDataSourceProxy(ds, plugin, c, proxyPath)
|
proxy := pluginproxy.NewDataSourceProxy(ds, plugin, c, proxyPath)
|
||||||
proxy.HandleRequest()
|
proxy.HandleRequest()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ensureProxyPathTrailingSlash Check for a trailing slash in original path and makes
|
||||||
|
// sure that a trailing slash is added to proxy path, if not already exists.
|
||||||
|
func ensureProxyPathTrailingSlash(originalPath, proxyPath string) string {
|
||||||
|
if len(proxyPath) > 1 {
|
||||||
|
if originalPath[len(originalPath)-1] == '/' && proxyPath[len(proxyPath)-1] != '/' {
|
||||||
|
return proxyPath + "/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return proxyPath
|
||||||
|
}
|
||||||
|
19
pkg/api/dataproxy_test.go
Normal file
19
pkg/api/dataproxy_test.go
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
. "github.com/smartystreets/goconvey/convey"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDataProxy(t *testing.T) {
|
||||||
|
Convey("Data proxy test", t, func() {
|
||||||
|
Convey("Should append trailing slash to proxy path if original path has a trailing slash", func() {
|
||||||
|
So(ensureProxyPathTrailingSlash("/api/datasources/proxy/6/api/v1/query_range/", "api/v1/query_range/"), ShouldEqual, "api/v1/query_range/")
|
||||||
|
})
|
||||||
|
|
||||||
|
Convey("Should not append trailing slash to proxy path if original path doesn't have a trailing slash", func() {
|
||||||
|
So(ensureProxyPathTrailingSlash("/api/datasources/proxy/6/api/v1/query_range", "api/v1/query_range"), ShouldEqual, "api/v1/query_range")
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user