Merge branch '13619-fed-object-list' closes #13619
[arvados.git] / lib / controller / handler.go
index 25799aae9ea30d3116469e205c77f927c313172a..0c31815cba21f2869e7ae4ddf73c880bf4d0a5c8 100644 (file)
@@ -68,7 +68,7 @@ func (h *Handler) setup() {
        })
        hs := http.NotFoundHandler()
        hs = prepend(hs, h.proxyRailsAPI)
-       hs = prepend(hs, h.proxyRemoteCluster)
+       hs = h.setupProxyRemoteCluster(hs)
        mux.Handle("/", hs)
        h.handlerStack = mux
 
@@ -121,11 +121,14 @@ func prepend(next http.Handler, middleware middlewareFunc) http.Handler {
        })
 }
 
-func (h *Handler) proxyRailsAPI(w http.ResponseWriter, req *http.Request, next http.Handler) {
+// localClusterRequest sets up a request so it can be proxied to the
+// local API server using proxy.Do().  Returns true if a response was
+// written, false if not.
+func (h *Handler) localClusterRequest(w http.ResponseWriter, req *http.Request, filter ResponseFilter) bool {
        urlOut, insecure, err := findRailsAPI(h.Cluster, h.NodeProfile)
        if err != nil {
                httpserver.Error(w, err.Error(), http.StatusInternalServerError)
-               return
+               return true
        }
        urlOut = &url.URL{
                Scheme:   urlOut.Scheme,
@@ -138,7 +141,13 @@ func (h *Handler) proxyRailsAPI(w http.ResponseWriter, req *http.Request, next h
        if insecure {
                client = h.insecureClient
        }
-       h.proxy.Do(w, req, urlOut, client)
+       return h.proxy.Do(w, req, urlOut, client, filter)
+}
+
+func (h *Handler) proxyRailsAPI(w http.ResponseWriter, req *http.Request, next http.Handler) {
+       if !h.localClusterRequest(w, req, nil) && next != nil {
+               next.ServeHTTP(w, req)
+       }
 }
 
 // For now, findRailsAPI always uses the rails API running on this