Skip to content

Commit

Permalink
Merge pull request #45 from avenga/fix-path-slash
Browse files Browse the repository at this point in the history
Fix wildcard path join with trailing slash
  • Loading branch information
Alex Schneider authored Oct 8, 2020
2 parents 97aa4c3 + 9aafeca commit d13a307
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions handler/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"net"
"net/http"
"net/url"
"path"
"strconv"
"strings"
"time"
Expand All @@ -26,6 +25,7 @@ import (
"github.com/avenga/couper/eval"
"github.com/avenga/couper/internal/seetie"
"github.com/avenga/couper/logging"
"github.com/avenga/couper/utils"
)

var (
Expand Down Expand Up @@ -284,7 +284,7 @@ func (p *Proxy) director(req *http.Request) {

if pathMatch, ok := req.Context().
Value(request.Wildcard).(string); ok && strings.HasSuffix(p.options.Path, "/**") {
req.URL.Path = path.Join(strings.ReplaceAll(p.options.Path, "/**", "/"), pathMatch)
req.URL.Path = utils.JoinPath(strings.ReplaceAll(p.options.Path, "/**", "/"), pathMatch)
} else if p.options.Path != "" {
req.URL.Path = p.options.Path
}
Expand Down
1 change: 1 addition & 0 deletions handler/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ func TestProxy_director(t *testing.T) {
{"proxy url settings", fields{eval.NewENVContext(nil), log.WithContext(nil), &ProxyOptions{Origin: "http://1.2.3.4", Context: emptyOptions}}, defaultReq, httptest.NewRequest("GET", "http://1.2.3.4", nil)},
{"proxy url settings w/hostname", fields{eval.NewENVContext(nil), log.WithContext(nil), &ProxyOptions{Origin: "http://1.2.3.4", Hostname: "couper.io", Context: emptyOptions}}, defaultReq, httptest.NewRequest("GET", "http://couper.io", nil)},
{"proxy url settings w/wildcard ctx", fields{eval.NewENVContext(nil), log.WithContext(nil), &ProxyOptions{Origin: "http://1.2.3.4", Hostname: "couper.io", Path: "/**", Context: emptyOptions}}, defaultReq.WithContext(context.WithValue(defaultReq.Context(), request.Wildcard, "/hans")), httptest.NewRequest("GET", "http://couper.io/hans", nil)},
{"proxy url settings w/wildcard ctx trailing slash", fields{eval.NewENVContext(nil), log.WithContext(nil), &ProxyOptions{Origin: "http://1.2.3.4", Hostname: "couper.io", Path: "/**", Context: emptyOptions}}, defaultReq.WithContext(context.WithValue(defaultReq.Context(), request.Wildcard, "/docs/")), httptest.NewRequest("GET", "http://couper.io/docs/", nil)},
}

for _, tt := range tests {
Expand Down

0 comments on commit d13a307

Please sign in to comment.