From 4f0e752d00890b7195f820cd53d7d66dc31d3bff Mon Sep 17 00:00:00 2001 From: Anthony Lapenna Date: Wed, 11 Apr 2018 17:40:29 +0200 Subject: [PATCH] feat(api): remove any version api before proxying request (#1806) --- api/http/proxy/transport.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/api/http/proxy/transport.go b/api/http/proxy/transport.go index 0e61dc1a5..98e15d29a 100644 --- a/api/http/proxy/transport.go +++ b/api/http/proxy/transport.go @@ -5,12 +5,15 @@ import ( "encoding/json" "net/http" "path" + "regexp" "strings" "github.com/portainer/portainer" "github.com/portainer/portainer/http/security" ) +var apiVersionRe = regexp.MustCompile(`(/v[0-9]\.[0-9]*)?`) + type ( proxyTransport struct { dockerTransport *http.Transport @@ -55,7 +58,8 @@ func (p *proxyTransport) executeDockerRequest(request *http.Request) (*http.Resp } func (p *proxyTransport) proxyDockerRequest(request *http.Request) (*http.Response, error) { - path := request.URL.Path + path := apiVersionRe.ReplaceAllString(request.URL.Path, "") + request.URL.Path = path switch { case strings.HasPrefix(path, "/configs"):