summaryrefslogtreecommitdiffstats
path: root/routers/api/v1
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2023-05-09 15:34:36 +0800
committerGitHub <noreply@github.com>2023-05-09 15:34:36 +0800
commit023a048f52b5bf8c4b715285245a129f04e05a8c (patch)
tree2ea5c0d940a9439e9760b00f735d869444d87165 /routers/api/v1
parentc090f87a8db5b51e0aa9c7278b38ddc862c048ac (diff)
downloadgitea-023a048f52b5bf8c4b715285245a129f04e05a8c.tar.gz
gitea-023a048f52b5bf8c4b715285245a129f04e05a8c.zip
Make repository response support HTTP range request (#24592)
Replace #20480 Replace #18448 Close #16414
Diffstat (limited to 'routers/api/v1')
-rw-r--r--routers/api/v1/repo/file.go19
1 files changed, 7 insertions, 12 deletions
diff --git a/routers/api/v1/repo/file.go b/routers/api/v1/repo/file.go
index 5f7ed255bc..eb63dda590 100644
--- a/routers/api/v1/repo/file.go
+++ b/routers/api/v1/repo/file.go
@@ -150,6 +150,7 @@ func GetRawFileOrLFS(ctx *context.APIContext) {
return
}
+ // FIXME: code from #19689, what if the file is large ... OOM ...
buf, err := io.ReadAll(dataRc)
if err != nil {
_ = dataRc.Close()
@@ -164,7 +165,7 @@ func GetRawFileOrLFS(ctx *context.APIContext) {
// Check if the blob represents a pointer
pointer, _ := lfs.ReadPointer(bytes.NewReader(buf))
- // if its not a pointer just serve the data directly
+ // if it's not a pointer, just serve the data directly
if !pointer.IsValid() {
// First handle caching for the blob
if httpcache.HandleGenericETagTimeCache(ctx.Req, ctx.Resp, `"`+blob.ID.String()+`"`, lastModified) {
@@ -172,25 +173,21 @@ func GetRawFileOrLFS(ctx *context.APIContext) {
}
// OK not cached - serve!
- if err := common.ServeData(ctx.Context, ctx.Repo.TreePath, blob.Size(), bytes.NewReader(buf)); err != nil {
- ctx.ServerError("ServeBlob", err)
- }
+ common.ServeContentByReader(ctx.Context, ctx.Repo.TreePath, blob.Size(), bytes.NewReader(buf))
return
}
- // Now check if there is a meta object for this pointer
+ // Now check if there is a MetaObject for this pointer
meta, err := git_model.GetLFSMetaObjectByOid(ctx, ctx.Repo.Repository.ID, pointer.Oid)
- // If there isn't one just serve the data directly
+ // If there isn't one, just serve the data directly
if err == git_model.ErrLFSObjectNotExist {
// Handle caching for the blob SHA (not the LFS object OID)
if httpcache.HandleGenericETagTimeCache(ctx.Req, ctx.Resp, `"`+blob.ID.String()+`"`, lastModified) {
return
}
- if err := common.ServeData(ctx.Context, ctx.Repo.TreePath, blob.Size(), bytes.NewReader(buf)); err != nil {
- ctx.ServerError("ServeBlob", err)
- }
+ common.ServeContentByReader(ctx.Context, ctx.Repo.TreePath, blob.Size(), bytes.NewReader(buf))
return
} else if err != nil {
ctx.ServerError("GetLFSMetaObjectByOid", err)
@@ -218,9 +215,7 @@ func GetRawFileOrLFS(ctx *context.APIContext) {
}
defer lfsDataRc.Close()
- if err := common.ServeData(ctx.Context, ctx.Repo.TreePath, meta.Size, lfsDataRc); err != nil {
- ctx.ServerError("ServeData", err)
- }
+ common.ServeContentByReadSeeker(ctx.Context, ctx.Repo.TreePath, lastModified, lfsDataRc)
}
func getBlobForEntry(ctx *context.APIContext) (blob *git.Blob, entry *git.TreeEntry, lastModified time.Time) {