aboutsummaryrefslogtreecommitdiffstats
path: root/routers/common/serve.go
diff options
context:
space:
mode:
Diffstat (limited to 'routers/common/serve.go')
-rw-r--r--routers/common/serve.go17
1 files changed, 13 insertions, 4 deletions
diff --git a/routers/common/serve.go b/routers/common/serve.go
index 446908db75..862230b30f 100644
--- a/routers/common/serve.go
+++ b/routers/common/serve.go
@@ -5,17 +5,21 @@ package common
import (
"io"
+ "path"
"time"
+ repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/httpcache"
"code.gitea.io/gitea/modules/httplib"
"code.gitea.io/gitea/modules/log"
+ "code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/services/context"
)
// ServeBlob download a git.Blob
-func ServeBlob(ctx *context.Base, filePath string, blob *git.Blob, lastModified *time.Time) error {
+func ServeBlob(ctx *context.Base, repo *repo_model.Repository, filePath string, blob *git.Blob, lastModified *time.Time) error {
if httpcache.HandleGenericETagTimeCache(ctx.Req, ctx.Resp, `"`+blob.ID.String()+`"`, lastModified) {
return nil
}
@@ -30,14 +34,19 @@ func ServeBlob(ctx *context.Base, filePath string, blob *git.Blob, lastModified
}
}()
- httplib.ServeContentByReader(ctx.Req, ctx.Resp, filePath, blob.Size(), dataRc)
+ _ = repo.LoadOwner(ctx)
+ httplib.ServeContentByReader(ctx.Req, ctx.Resp, blob.Size(), dataRc, &httplib.ServeHeaderOptions{
+ Filename: path.Base(filePath),
+ CacheIsPublic: !repo.IsPrivate && repo.Owner != nil && repo.Owner.Visibility == structs.VisibleTypePublic,
+ CacheDuration: setting.StaticCacheTime,
+ })
return nil
}
func ServeContentByReader(ctx *context.Base, filePath string, size int64, reader io.Reader) {
- httplib.ServeContentByReader(ctx.Req, ctx.Resp, filePath, size, reader)
+ httplib.ServeContentByReader(ctx.Req, ctx.Resp, size, reader, &httplib.ServeHeaderOptions{Filename: path.Base(filePath)})
}
func ServeContentByReadSeeker(ctx *context.Base, filePath string, modTime *time.Time, reader io.ReadSeeker) {
- httplib.ServeContentByReadSeeker(ctx.Req, ctx.Resp, filePath, modTime, reader)
+ httplib.ServeContentByReadSeeker(ctx.Req, ctx.Resp, modTime, reader, &httplib.ServeHeaderOptions{Filename: path.Base(filePath)})
}