mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-31 20:02:09 +00:00
fix artifact range requests (#4218)
I noticed that Forgejo does not allow HTTP range requests when downloading artifacts. All other file downloads like releases and packages support them. So I looked at the code and found that the artifact download endpoint uses a simple io.Copy to serve the file contents instead of using the established `ServeContentByReadSeeker` function which does take range requests into account. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4218 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: ThetaDev <thetadev@magenta.de> Co-committed-by: ThetaDev <thetadev@magenta.de>
This commit is contained in:
parent
928f188689
commit
e80f8ff69f
4 changed files with 73 additions and 11 deletions
|
@ -97,6 +97,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/storage"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/routers/common"
|
||||
"code.gitea.io/gitea/services/context"
|
||||
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
|
@ -473,9 +474,14 @@ func (r *artifactV4Routes) downloadArtifact(ctx *ArtifactContext) {
|
|||
return
|
||||
}
|
||||
|
||||
file, _ := r.fs.Open(artifact.StoragePath)
|
||||
file, err := r.fs.Open(artifact.StoragePath)
|
||||
if err != nil {
|
||||
log.Error("Error artifact could not be opened: %v", err)
|
||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
_, _ = io.Copy(ctx.Resp, file)
|
||||
common.ServeContentByReadSeeker(ctx.Base, artifactName, util.ToPointer(artifact.UpdatedUnix.AsTime()), file)
|
||||
}
|
||||
|
||||
func (r *artifactV4Routes) deleteArtifact(ctx *ArtifactContext) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue