feat(api): remove any version api before proxying request (#1806)

pull/1809/head
Anthony Lapenna 2018-04-11 17:40:29 +02:00 committed by GitHub
parent 2a9ba1f9a2
commit 4f0e752d00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -5,12 +5,15 @@ import (
"encoding/json" "encoding/json"
"net/http" "net/http"
"path" "path"
"regexp"
"strings" "strings"
"github.com/portainer/portainer" "github.com/portainer/portainer"
"github.com/portainer/portainer/http/security" "github.com/portainer/portainer/http/security"
) )
var apiVersionRe = regexp.MustCompile(`(/v[0-9]\.[0-9]*)?`)
type ( type (
proxyTransport struct { proxyTransport struct {
dockerTransport *http.Transport 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) { 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 { switch {
case strings.HasPrefix(path, "/configs"): case strings.HasPrefix(path, "/configs"):