From 390b903c555381286751a16c27a3da23b5969693 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Thu, 24 Oct 2019 19:56:09 -0700 Subject: web: fix panic when download attachments (#5838) --- internal/cmd/web.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'internal/cmd') 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 } }) -- cgit v1.2.3