~emersion/public-inbox

kimchi: Fix stripping trailing slash when forwarding v1 SUPERSEDED

Krystian Chachuła: 1
 Fix stripping trailing slash when forwarding

 1 files changed, 2 insertions(+), 4 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~emersion/public-inbox/patches/54277/mbox | git am -3
Learn more about email & git

[PATCH kimchi] Fix stripping trailing slash when forwarding Export this patch

path.Join strips trailing slashes. This leads to redirection loops when
the backend enforces trailing slashes by redirecting. This commit
replaces path.Join with URL.JoinPath, which doesn't strip trailing
slashes.

---
The additional req.URL.Path != "" condition is for cases where target
URL ends with a slash and request path is / (""). Then, the final
request path will end with a slash.

 directives.go | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/directives.go b/directives.go
index 94258d3..5986302 100644
--- a/directives.go
+++ b/directives.go
@@ -8,7 +8,6 @@ import (
	"net/http/httputil"
	"net/url"
	"os"
	"path"
	"path/filepath"
	"strings"
	"time"
@@ -224,9 +223,8 @@ var backends = map[string]parseBackendFunc{

			req.URL.Scheme = target.Scheme
			req.URL.Host = target.Host
			if strings.HasSuffix(target.Path, "/") {
				p := path.Join("/", req.URL.Path)
				req.URL.Path = strings.TrimSuffix(target.Path, "/") + p
			if strings.HasSuffix(target.Path, "/") && req.URL.Path != "" {
				req.URL = target.JoinPath(req.URL.Path)
			} else {
				req.URL.Path = target.Path
			}
-- 
2.45.1
Hm, can we make it so only req.URL.Path is affected here, rather than
overwriting the whole URL? Otherwise the logic below includes the raw
query twice.