aboutsummaryrefslogtreecommitdiff
path: root/internal/cmd
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/cmd
parent1ba27853bd69d96691686a60f12031f001d7e75c (diff)
web: fix panic when download attachments (#5838)
Diffstat (limited to 'internal/cmd')
-rw-r--r--internal/cmd/web.go9
1 files changed, 5 insertions, 4 deletions
diff --git a/internal/cmd/web.go b/internal/cmd/web.go
index 709bc0df..f08854a4 100644
--- a/internal/cmd/web.go
+++ b/internal/cmd/web.go
@@ -7,6 +7,7 @@ package cmd
import (
"crypto/tls"
"fmt"
+ "io"
"io/ioutil"
"net"
"net/http"
@@ -322,16 +323,16 @@ func runWeb(c *cli.Context) error {
fr, err := os.Open(attach.LocalPath())
if err != nil {
- c.Handle(500, "Open", err)
+ c.ServerError("open attachment file", err)
return
}
defer fr.Close()
c.Header().Set("Cache-Control", "public,max-age=86400")
- fmt.Println("attach.Name:", attach.Name)
c.Header().Set("Content-Disposition", fmt.Sprintf(`inline; filename="%s"`, attach.Name))
- if err = repo.ServeData(c, attach.Name, fr); err != nil {
- c.Handle(500, "ServeData", err)
+
+ if _, err = io.Copy(c.Resp, fr); err != nil {
+ c.ServerError("copy from file to response", err)
return
}
})