12134: Revert "10805: Skip llfuse.close() to avoid llfuse deadlocks in test suite."
[arvados.git] / services / keep-web / handler.go
index 56484490a462822ea7e6300864f383b711c395a9..67d46f6716b2ce22b09cb6b1204b08fdb3c3dd96 100644 (file)
@@ -27,10 +27,10 @@ import (
 )
 
 type handler struct {
-       Config     *Config
-       clientPool *arvadosclient.ClientPool
-       setupOnce  sync.Once
-       hmux       *http.ServeMux
+       Config        *Config
+       clientPool    *arvadosclient.ClientPool
+       setupOnce     sync.Once
+       healthHandler http.Handler
 }
 
 // parseCollectionIDFromDNSName returns a UUID or PDH if s begins with
@@ -75,11 +75,10 @@ func (h *handler) setup() {
 
        keepclient.RefreshServiceDiscoveryOnSIGHUP()
 
-       h.hmux = http.NewServeMux()
-       h.hmux.Handle("/_health/", &health.Handler{
+       h.healthHandler = &health.Handler{
                Token:  h.Config.ManagementToken,
                Prefix: "/_health/",
-       })
+       }
 }
 
 func (h *handler) serveStatus(w http.ResponseWriter, r *http.Request) {
@@ -91,10 +90,6 @@ func (h *handler) serveStatus(w http.ResponseWriter, r *http.Request) {
        json.NewEncoder(w).Encode(status)
 }
 
-func (h *handler) healthCheck(w http.ResponseWriter, r *http.Request) {
-       h.hmux.ServeHTTP(w, r)
-}
-
 // ServeHTTP implements http.Handler.
 func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
        h.setupOnce.Do(h.setup)
@@ -124,7 +119,7 @@ func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
        }()
 
        if strings.HasPrefix(r.URL.Path, "/_health/") && r.Method == "GET" {
-               h.healthCheck(w, r)
+               h.healthHandler.ServeHTTP(w, r)
                return
        }
 
@@ -154,6 +149,7 @@ func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
                // SSL certificates. See
                // http://www.w3.org/TR/cors/#user-credentials).
                w.Header().Set("Access-Control-Allow-Origin", "*")
+               w.Header().Set("Access-Control-Expose-Headers", "Content-Range")
        }
 
        arv := h.clientPool.Get()