mirror of https://github.com/portainer/portainer
feat(api): remove any version api before proxying request (#1806)
parent
2a9ba1f9a2
commit
4f0e752d00
|
@ -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"):
|
||||||
|
|
Loading…
Reference in New Issue