path.Join strips trailing slashes. This leads to redirection loops when
the backend enforces trailing slashes by redirecting. This commit adds
the trailing slashes back.
---
Thanks for the review of v1. I looked up how URL.JoinPath deals with
trailing slashes. It adds them back like this.
directives.go | 3 +++
1 file changed, 3 insertions(+)
diff --git a/directives.go b/directives.go
index 94258d3..5ec62a2 100644
--- a/directives.go+++ b/directives.go
@@ -226,6 +226,9 @@ var backends = map[string]parseBackendFunc{
req.URL.Host = target.Host
if strings.HasSuffix(target.Path, "/") {
p := path.Join("/", req.URL.Path)
+ if strings.HasSuffix(req.URL.Path, "/") && !strings.HasSuffix(p, "/") {+ p += "/"+ } req.URL.Path = strings.TrimSuffix(target.Path, "/") + p
} else {
req.URL.Path = target.Path
--
2.45.1