diff --git a/appview/repo/blob.go b/appview/repo/blob.go index 4785633e..047baef7 100644 --- a/appview/repo/blob.go +++ b/appview/repo/blob.go @@ -139,29 +139,26 @@ func (rp *Repo) Blob(w http.ResponseWriter, r *http.Request) { FileTooLarge: false, Contents: "", Lines: 0, - SizeHint: uint64(max(blobResp.ContentLength, 0)), + SizeHint: uint64(resp.Size), }, nil } // skip large blobs - if blobResp.ContentLength > maxBlobSize || blobResp.ContentLength < 0 { - l.Error("large blob:", "ContentLength", blobResp.ContentLength, "maxBlobSize", maxBlobSize) - } - - content, err := io.ReadAll(io.LimitReader(blobResp.Body, maxBlobSize+1)) - if err != nil { - return models.BlobView{}, err - } - - if int64(len(content)) > maxBlobSize { + if resp.Size > maxBlobSize { return models.BlobView{ ContentType: contentType, ContentSrc: blobUrl, FileTooLarge: true, - SizeHint: uint64(max(blobResp.ContentLength, 0)), + SizeHint: uint64(resp.Size), }, nil } + // just in case, ensure the size again + content, err := io.ReadAll(io.LimitReader(blobResp.Body, maxBlobSize)) + if err != nil { + return models.BlobView{}, err + } + contentStr := string(content) return models.BlobView{ ContentType: contentType, @@ -169,7 +166,7 @@ func (rp *Repo) Blob(w http.ResponseWriter, r *http.Request) { Contents: contentStr, FileTooLarge: false, Lines: countLines(contentStr), - SizeHint: uint64(len(content)), + SizeHint: uint64(resp.Size), }, nil }() if err != nil {