X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/98911cfe4792b20798858cefb353c451460e1a80..9cc572d6a44262e21251372e28b549cfc09e681a:/services/keep-web/handler.go diff --git a/services/keep-web/handler.go b/services/keep-web/handler.go index 8b61b54b97..d0ba431aa6 100644 --- a/services/keep-web/handler.go +++ b/services/keep-web/handler.go @@ -10,7 +10,6 @@ import ( "html" "html/template" "io" - "log" "net/http" "net/url" "os" @@ -26,11 +25,13 @@ import ( "git.curoverse.com/arvados.git/sdk/go/health" "git.curoverse.com/arvados.git/sdk/go/httpserver" "git.curoverse.com/arvados.git/sdk/go/keepclient" + log "github.com/Sirupsen/logrus" "golang.org/x/net/webdav" ) type handler struct { Config *Config + MetricsAPI http.Handler clientPool *arvadosclient.ClientPool setupOnce sync.Once healthHandler http.Handler @@ -183,6 +184,9 @@ func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) { if xff := r.Header.Get("X-Forwarded-For"); xff != "" { remoteAddr = xff + "," + remoteAddr } + if xfp := r.Header.Get("X-Forwarded-Proto"); xfp != "" && xfp != "http" { + r.URL.Scheme = xfp + } w := httpserver.WrapResponseWriter(wOrig) defer func() { @@ -191,13 +195,12 @@ func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) { } else if w.WroteStatus() == 0 { w.WriteHeader(statusCode) } else if w.WroteStatus() != statusCode { - httpserver.Log(r.RemoteAddr, "WARNING", + log.WithField("RequestID", r.Header.Get("X-Request-Id")).Warn( fmt.Sprintf("Our status changed from %d to %d after we sent headers", w.WroteStatus(), statusCode)) } if statusText == "" { statusText = http.StatusText(statusCode) } - httpserver.Log(remoteAddr, statusCode, statusText, w.WroteBodyBytes(), r.Method, r.Host, r.URL.Path, r.URL.RawQuery) }() if strings.HasPrefix(r.URL.Path, "/_health/") && r.Method == "GET" { @@ -257,6 +260,9 @@ func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) { } else if r.URL.Path == "/status.json" { h.serveStatus(w, r) return + } else if strings.HasPrefix(r.URL.Path, "/metrics") { + h.MetricsAPI.ServeHTTP(w, r) + return } else if siteFSDir[pathParts[0]] { useSiteFS = true } else if len(pathParts) >= 1 && strings.HasPrefix(pathParts[0], "c=") { @@ -314,6 +320,14 @@ func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) { return } + if useSiteFS { + if tokens == nil { + tokens = auth.NewCredentialsFromHTTPRequest(r).Tokens + } + h.serveSiteFS(w, r, tokens, credentialsOK, attachment) + return + } + targetPath := pathParts[stripParts:] if tokens == nil && len(targetPath) > 0 && strings.HasPrefix(targetPath[0], "t=") { // http://ID.example/t=TOKEN/PATH... @@ -335,11 +349,6 @@ func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) { tokens = append(reqTokens, h.Config.AnonymousTokens...) } - if useSiteFS { - h.serveSiteFS(w, r, tokens, credentialsOK, attachment) - return - } - if len(targetPath) > 0 && targetPath[0] == "_" { // If a collection has a directory called "t=foo" or // "_", it can be served at @@ -417,6 +426,7 @@ func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) { statusCode, statusText = http.StatusInternalServerError, err.Error() return } + kc.RequestID = r.Header.Get("X-Request-Id") var basename string if len(targetPath) > 0 { @@ -424,11 +434,11 @@ func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) { } applyContentDispositionHdr(w, r, basename, attachment) - client := &arvados.Client{ + client := (&arvados.Client{ APIHost: arv.ApiServer, AuthToken: arv.ApiToken, Insecure: arv.ApiInsecure, - } + }).WithRequestID(r.Header.Get("X-Request-Id")) fs, err := collection.FileSystem(client, kc) if err != nil { @@ -529,11 +539,12 @@ func (h *handler) serveSiteFS(w http.ResponseWriter, r *http.Request, tokens []s http.Error(w, err.Error(), http.StatusInternalServerError) return } - client := &arvados.Client{ + kc.RequestID = r.Header.Get("X-Request-Id") + client := (&arvados.Client{ APIHost: arv.ApiServer, AuthToken: arv.ApiToken, Insecure: arv.ApiInsecure, - } + }).WithRequestID(r.Header.Get("X-Request-Id")) fs := client.SiteFileSystem(kc) f, err := fs.Open(r.URL.Path) if os.IsNotExist(err) { @@ -615,9 +626,9 @@ the entire directory tree with wget, try:

@@ -769,6 +780,7 @@ func (h *handler) seeOtherWithCookie(w http.ResponseWriter, r *http.Request, loc u = newu } redir := (&url.URL{ + Scheme: r.URL.Scheme, Host: r.Host, Path: u.Path, RawQuery: redirQuery.Encode(),