From 53b91ef306166d39dea3c70fb8ce14973c7ae111 Mon Sep 17 00:00:00 2001 From: ᴜɴᴋɴᴡᴏɴ Date: Sun, 5 Apr 2020 00:14:22 +0800 Subject: lfs: run e2e and fix minor issues (#6059) --- internal/route/lfs/basic.go | 3 +-- internal/route/lfs/batch.go | 4 ++-- internal/route/lfs/route.go | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) (limited to 'internal/route') diff --git a/internal/route/lfs/basic.go b/internal/route/lfs/basic.go index 98597345..f15873ad 100644 --- a/internal/route/lfs/basic.go +++ b/internal/route/lfs/basic.go @@ -52,14 +52,13 @@ func serveBasicDownload(c *context.Context, repo *db.Repository, oid lfsutil.OID c.Header().Set("Content-Type", "application/octet-stream") c.Header().Set("Content-Length", strconv.FormatInt(object.Size, 10)) + c.Status(http.StatusOK) _, err = io.Copy(c.Resp, r) if err != nil { - c.Status(http.StatusInternalServerError) log.Error("Failed to copy object file: %v", err) return } - c.Status(http.StatusOK) } // PUT /{owner}/{repo}.git/info/lfs/object/basic/{oid} diff --git a/internal/route/lfs/batch.go b/internal/route/lfs/batch.go index ae53f5d3..357aeace 100644 --- a/internal/route/lfs/batch.go +++ b/internal/route/lfs/batch.go @@ -166,13 +166,13 @@ const contentType = "application/vnd.git-lfs+json" func responseJSON(w http.ResponseWriter, status int, v interface{}) { w.Header().Set("Content-Type", contentType) + w.WriteHeader(status) err := jsoniter.NewEncoder(w).Encode(v) if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) + log.Error("Failed to encode JSON: %v", err) return } - w.WriteHeader(status) } func internalServerError(w http.ResponseWriter) { diff --git a/internal/route/lfs/route.go b/internal/route/lfs/route.go index 27224265..b6bd20bf 100644 --- a/internal/route/lfs/route.go +++ b/internal/route/lfs/route.go @@ -134,11 +134,11 @@ func authorize(mode db.AccessMode) macaron.Handler { } } -// verifyHeader checks if the HTTP header value is matching. +// verifyHeader checks if the HTTP header contains given value. // When not, response given "failCode" as status code. func verifyHeader(key, value string, failCode int) macaron.Handler { return func(c *context.Context) { - if c.Req.Header.Get(key) != value { + if !strings.Contains(c.Req.Header.Get(key), value) { c.Status(failCode) return } -- cgit v1.2.3