mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Merge pull request #6114 from GoogleCloudPlatform/revert-6048-proxy
Revert "Updating proxy to return 301 to add a "/" at the end for #4958"
This commit is contained in:
commit
04e49240b5
@ -191,15 +191,6 @@ func (r *ProxyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||||||
return
|
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, "/") {
|
|
||||||
w.Header().Set("Location", req.URL.Path+"/")
|
|
||||||
w.WriteHeader(http.StatusMovedPermanently)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
proxy := httputil.NewSingleHostReverseProxy(&url.URL{Scheme: location.Scheme, Host: location.Host})
|
proxy := httputil.NewSingleHostReverseProxy(&url.URL{Scheme: location.Scheme, Host: location.Host})
|
||||||
if transport == nil {
|
if transport == nil {
|
||||||
prepend := path.Join(r.prefix, resource, id)
|
prepend := path.Join(r.prefix, resource, id)
|
||||||
|
@ -367,59 +367,3 @@ func TestProxyUpgrade(t *testing.T) {
|
|||||||
t.Fatalf("expected '%#v', got '%#v'", e, a)
|
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
|
|
||||||
}{
|
|
||||||
{"/trailing/slash/", "/trailing/slash/"},
|
|
||||||
{"/", "/"},
|
|
||||||
// "/" should be added at the end.
|
|
||||||
{"", "/"},
|
|
||||||
// "/" 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)
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
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/version/proxy/namespaces/ns/foo/id" + item.path
|
|
||||||
req, err := http.NewRequest(
|
|
||||||
"GET",
|
|
||||||
server.URL+proxyTestPattern,
|
|
||||||
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 != 200 {
|
|
||||||
t.Errorf("Unexpected errorCode: %v, expected: 200. Response: %v, item: %v", resp.StatusCode, resp, item)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user