Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APIServer: Updating special verb handlers to accept full request path rather than a trimmed one #4768

Merged
merged 1 commit into from
Feb 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 7 additions & 8 deletions pkg/apiserver/api_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ func (a *APIInstaller) Install() (ws *restful.WebService, errors []error) {
watchHandler := (&WatchHandler{
storage: a.group.storage,
codec: a.group.codec,
prefix: a.group.prefix,
linker: a.group.linker,
info: a.group.info,
})
Expand Down Expand Up @@ -274,23 +273,23 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage RESTStorage
addParams(route, action.Params)
ws.Route(route)
case "WATCH": // Watch a resource.
route := ws.GET(action.Path).To(restfulStripPrefix(a.prefix+"/watch", watchHandler)).
route := ws.GET(action.Path).To(routeFunction(watchHandler)).
Filter(m).
Doc("watch a particular " + kind).
Operation("watch" + kind).
Writes(versionedObject)
addParams(route, action.Params)
ws.Route(route)
case "WATCHLIST": // Watch all resources of a kind.
route := ws.GET(action.Path).To(restfulStripPrefix(a.prefix+"/watch", watchHandler)).
route := ws.GET(action.Path).To(routeFunction(watchHandler)).
Filter(m).
Doc("watch a list of " + kind).
Operation("watch" + kind + "list").
Writes(versionedList)
addParams(route, action.Params)
ws.Route(route)
case "REDIRECT": // Get the redirect URL for a resource.
route := ws.GET(action.Path).To(restfulStripPrefix(a.prefix+"/redirect", redirectHandler)).
route := ws.GET(action.Path).To(routeFunction(redirectHandler)).
Filter(m).
Doc("redirect GET request to " + kind).
Operation("redirect" + kind).
Expand Down Expand Up @@ -542,15 +541,15 @@ func appendIf(actions []action, a action, shouldAppend bool) []action {
return actions
}

// Returns a restful RouteFunction that calls the given handler after stripping prefix from the request path.
func restfulStripPrefix(prefix string, handler http.Handler) restful.RouteFunction {
// Wraps a http.Handler function inside a restful.RouteFunction
func routeFunction(handler http.Handler) restful.RouteFunction {
return func(restReq *restful.Request, restResp *restful.Response) {
http.StripPrefix(prefix, handler).ServeHTTP(restResp.ResponseWriter, restReq.Request)
handler.ServeHTTP(restResp.ResponseWriter, restReq.Request)
}
}

func addProxyRoute(ws *restful.WebService, method string, prefix string, path string, proxyHandler http.Handler, kind, resource string, params []*restful.Parameter) {
proxyRoute := ws.Method(method).Path(path).To(restfulStripPrefix(prefix+"/proxy", proxyHandler)).
proxyRoute := ws.Method(method).Path(path).To(routeFunction(proxyHandler)).
Filter(monitorFilter("PROXY", resource)).
Doc("proxy " + method + " requests to " + kind).
Operation("proxy" + method + kind).
Expand Down
2 changes: 1 addition & 1 deletion pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func NewAPIGroupVersion(storage map[string]RESTStorage, codec runtime.Codec, roo
admit: admissionControl,
context: contextMapper,
mapper: mapper,
info: &APIRequestInfoResolver{util.NewStringSet(root), latest.RESTMapper},
info: &APIRequestInfoResolver{util.NewStringSet(strings.TrimPrefix(root, "/")), latest.RESTMapper},
}
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/apiserver/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import (
type WatchHandler struct {
storage map[string]RESTStorage
codec runtime.Codec
prefix string
linker runtime.SelfLinker
info *APIRequestInfoResolver
}
Expand All @@ -51,7 +50,7 @@ func (h *WatchHandler) setSelfLinkAddName(obj runtime.Object, req *http.Request)
return err
}
newURL := *req.URL
newURL.Path = path.Join(h.prefix, req.URL.Path, name)
newURL.Path = path.Join(req.URL.Path, name)
newURL.RawQuery = ""
newURL.Fragment = ""
return h.linker.SetSelfLink(obj, newURL.String())
Expand Down