aboutsummaryrefslogtreecommitdiff
path: root/internal/route/repo/download.go
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2019-10-24 19:56:09 -0700
committerUnknwon <u@gogs.io>2019-10-24 19:58:30 -0700
commit390b903c555381286751a16c27a3da23b5969693 (patch)
tree613bd6067f3f1436ae4809d9a5834f5b15ed5e8f /internal/route/repo/download.go
parent1ba27853bd69d96691686a60f12031f001d7e75c (diff)
web: fix panic when download attachments (#5838)
Diffstat (limited to 'internal/route/repo/download.go')
-rw-r--r--internal/route/repo/download.go13
1 files changed, 8 insertions, 5 deletions
diff --git a/internal/route/repo/download.go b/internal/route/repo/download.go
index 88b75082..65c3c125 100644
--- a/internal/route/repo/download.go
+++ b/internal/route/repo/download.go
@@ -17,9 +17,9 @@ import (
"gogs.io/gogs/internal/tool"
)
-func ServeData(c *context.Context, name string, reader io.Reader) error {
+func serveData(c *context.Context, name string, r io.Reader) error {
buf := make([]byte, 1024)
- n, _ := reader.Read(buf)
+ n, _ := r.Read(buf)
if n >= 0 {
buf = buf[:n]
}
@@ -38,8 +38,11 @@ func ServeData(c *context.Context, name string, reader io.Reader) error {
} else if !setting.Repository.EnableRawFileRenderMode || !c.QueryBool("render") {
c.Resp.Header().Set("Content-Type", "text/plain; charset=utf-8")
}
- c.Resp.Write(buf)
- _, err = io.Copy(c.Resp, reader)
+
+ if _, err := c.Resp.Write(buf); err != nil {
+ return fmt.Errorf("write buffer to response: %v", err)
+ }
+ _, err = io.Copy(c.Resp, r)
return err
}
@@ -49,7 +52,7 @@ func ServeBlob(c *context.Context, blob *git.Blob) error {
return err
}
- return ServeData(c, path.Base(c.Repo.TreePath), dataRc)
+ return serveData(c, path.Base(c.Repo.TreePath), dataRc)
}
func SingleDownload(c *context.Context) {