X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/e14e011f667d314e557c580de69a271534b6149f..8e39b792a728d460d9ed439f664d54aac5432168:/services/arv-git-httpd/auth_handler.go diff --git a/services/arv-git-httpd/auth_handler.go b/services/arv-git-httpd/auth_handler.go index 741e543850..fccb0c9576 100644 --- a/services/arv-git-httpd/auth_handler.go +++ b/services/arv-git-httpd/auth_handler.go @@ -3,10 +3,8 @@ package main import ( "log" "net/http" - "net/http/cgi" "os" "strings" - "sync" "time" "git.curoverse.com/arvados.git/sdk/go/arvadosclient" @@ -14,19 +12,10 @@ import ( "git.curoverse.com/arvados.git/sdk/go/httpserver" ) -func newArvadosClient() interface{} { - arv, err := arvadosclient.MakeArvadosClient() - if err != nil { - log.Println("MakeArvadosClient:", err) - return nil - } - return &arv -} - -var connectionPool = &sync.Pool{New: newArvadosClient} +var clientPool = arvadosclient.MakeClientPool() type authHandler struct { - handler *cgi.Handler + handler http.Handler } func (h *authHandler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) { @@ -79,12 +68,12 @@ func (h *authHandler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) { repoName = pathParts[0] repoName = strings.TrimRight(repoName, "/") - arv, ok := connectionPool.Get().(*arvadosclient.ArvadosClient) - if !ok || arv == nil { - statusCode, statusText = http.StatusInternalServerError, "connection pool failed" + arv := clientPool.Get() + if arv == nil { + statusCode, statusText = http.StatusInternalServerError, "connection pool failed: "+clientPool.Err().Error() return } - defer connectionPool.Put(arv) + defer clientPool.Put(arv) // Ask API server whether the repository is readable using // this token (by trying to read it!) @@ -160,7 +149,5 @@ func (h *authHandler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) { } r.URL.Path = rewrittenPath - handlerCopy := *h.handler - handlerCopy.Env = append(handlerCopy.Env, "REMOTE_USER="+r.RemoteAddr) // Should be username - handlerCopy.ServeHTTP(&w, r) + h.handler.ServeHTTP(&w, r) }