From 6f641744ff1f974dc0f699480a941dff8c151043 Mon Sep 17 00:00:00 2001 From: Anthony Yeh Date: Wed, 14 Jan 2015 21:42:34 -0800 Subject: [PATCH] Preserve trailing slash in apiserver proxy. Some servers are sensitive to the presence of a trailing slash. For example, http://etcd/v2/keys returns 404 while http://etcd/v2/keys/ returns the key named "/". --- pkg/apiserver/proxy.go | 6 ++++++ pkg/apiserver/proxy_test.go | 1 + 2 files changed, 7 insertions(+) diff --git a/pkg/apiserver/proxy.go b/pkg/apiserver/proxy.go index edaed7423b9..138a992d755 100644 --- a/pkg/apiserver/proxy.go +++ b/pkg/apiserver/proxy.go @@ -96,6 +96,12 @@ func (r *ProxyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { if len(parts) > 2 { proxyParts := parts[2:] rest = strings.Join(proxyParts, "/") + if strings.HasSuffix(req.URL.Path, "/") { + // The original path had a trailing slash, which has been stripped + // by KindAndNamespace(). We should add it back because some + // servers (like etcd) require it. + rest = rest + "/" + } } storage, ok := r.storage[kind] if !ok { diff --git a/pkg/apiserver/proxy_test.go b/pkg/apiserver/proxy_test.go index fdc9954af95..42e08d1728c 100644 --- a/pkg/apiserver/proxy_test.go +++ b/pkg/apiserver/proxy_test.go @@ -147,6 +147,7 @@ func TestProxy(t *testing.T) { {"PUT", "/some/dir/id", "different question", "answer", "text/css", "default"}, {"DELETE", "/some/dir/id", "", "ok", "text/css", "default"}, {"GET", "/some/dir/id", "", "answer", "text/css", "other"}, + {"GET", "/trailing/slash/", "", "answer", "text/css", "default"}, } for _, item := range table {