Commit 3fa80881 by Marcus Efraimsson

dataproxy should forward a trailing slash to proxy

parent 8bf4d680
...@@ -51,17 +51,21 @@ func (hs *HTTPServer) ProxyDataSourceRequest(c *m.ReqContext) { ...@@ -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
proxyPath := ensureProxyPathTrailingSlash(c.Req.URL.Path, c.Params("*"))
proxy := pluginproxy.NewDataSourceProxy(ds, plugin, c, proxyPath)
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 len(proxyPath) > 1 {
path := c.Req.URL.Path if originalPath[len(originalPath)-1] == '/' && proxyPath[len(proxyPath)-1] != '/' {
if path[len(path)-1] == '/' && proxyPath[len(proxyPath)-1] != '/' { return proxyPath + "/"
proxyPath += "/"
} }
} }
proxy := pluginproxy.NewDataSourceProxy(ds, plugin, c, proxyPath) return proxyPath
proxy.HandleRequest()
} }
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")
})
})
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment