diff --git a/pkg/apiserver/proxy.go b/pkg/apiserver/proxy.go index a7a538c4abfc2..3e367ae3e225e 100644 --- a/pkg/apiserver/proxy.go +++ b/pkg/apiserver/proxy.go @@ -168,19 +168,6 @@ func (r *ProxyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - // Redirect requests of the form "/{resource}/{name}" to "/{resource}/{name}/" - // This is essentially a hack for https://github.com/GoogleCloudPlatform/kubernetes/issues/4958. - // Note: Keep this code after tryUpgrade to not break that flow. - if len(parts) == 2 && !strings.HasSuffix(req.URL.Path, "/") { - var queryPart string - if len(req.URL.RawQuery) > 0 { - queryPart = "?" + req.URL.RawQuery - } - w.Header().Set("Location", req.URL.Path+"/"+queryPart) - w.WriteHeader(http.StatusMovedPermanently) - return - } - start := time.Now() glog.V(4).Infof("[%x] Beginning proxy %s...", proxyHandlerTraceID, req.URL) defer func() { diff --git a/pkg/apiserver/proxy_test.go b/pkg/apiserver/proxy_test.go index bc66097089edd..854f4baa476ed 100644 --- a/pkg/apiserver/proxy_test.go +++ b/pkg/apiserver/proxy_test.go @@ -164,64 +164,3 @@ func TestProxyUpgrade(t *testing.T) { t.Fatalf("expected '%#v', got '%#v'", e, a) } } - -func TestRedirectOnMissingTrailingSlash(t *testing.T) { - table := []struct { - // The requested path - path string - // The path requested on the proxy server. - proxyServerPath string - // query string - query string - }{ - {"/trailing/slash/", "/trailing/slash/", ""}, - {"/", "/", "test1=value1&test2=value2"}, - // "/" should be added at the end. - {"", "/", "test1=value1&test2=value2"}, - // "/" should not be added at a non-root path. - {"/some/path", "/some/path", ""}, - } - - for _, item := range table { - proxyServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { - if req.URL.Path != item.proxyServerPath { - t.Errorf("Unexpected request on path: %s, expected path: %s, item: %v", req.URL.Path, item.proxyServerPath, item) - } - if req.URL.RawQuery != item.query { - t.Errorf("Unexpected query on url: %s, expected: %s", req.URL.RawQuery, item.query) - } - })) - defer proxyServer.Close() - - serverURL, _ := url.Parse(proxyServer.URL) - simpleStorage := &SimpleRESTStorage{ - errors: map[string]error{}, - resourceLocation: serverURL, - expectedResourceNamespace: "ns", - } - - handler := handleNamespaced(map[string]rest.Storage{"foo": simpleStorage}) - server := httptest.NewServer(handler) - defer server.Close() - - proxyTestPattern := "/api/version2/proxy/namespaces/ns/foo/id" + item.path - req, err := http.NewRequest( - "GET", - server.URL+proxyTestPattern+"?"+item.query, - strings.NewReader(""), - ) - if err != nil { - t.Errorf("unexpected error %v", err) - continue - } - // Note: We are using a default client here, that follows redirects. - resp, err := http.DefaultClient.Do(req) - if err != nil { - t.Errorf("unexpected error %v", err) - continue - } - if resp.StatusCode != http.StatusOK { - t.Errorf("Unexpected errorCode: %v, expected: 200. Response: %v, item: %v", resp.StatusCode, resp, item) - } - } -} diff --git a/pkg/registry/generic/rest/proxy.go b/pkg/registry/generic/rest/proxy.go index 5339c596f4696..085a4eb0af0f4 100644 --- a/pkg/registry/generic/rest/proxy.go +++ b/pkg/registry/generic/rest/proxy.go @@ -85,20 +85,6 @@ func (h *UpgradeAwareProxyHandler) ServeHTTP(w http.ResponseWriter, req *http.Re loc.Path += "/" } - // From pkg/apiserver/proxy.go#ServeHTTP: - // Redirect requests with an empty path to a location that ends with a '/' - // This is essentially a hack for https://github.com/GoogleCloudPlatform/kubernetes/issues/4958. - // Note: Keep this code after tryUpgrade to not break that flow. - if len(loc.Path) == 0 { - var queryPart string - if len(req.URL.RawQuery) > 0 { - queryPart = "?" + req.URL.RawQuery - } - w.Header().Set("Location", req.URL.Path+"/"+queryPart) - w.WriteHeader(http.StatusMovedPermanently) - return - } - if h.Transport == nil { h.Transport = h.defaultProxyTransport(req.URL) }