diff options
-rw-r--r-- | gogs.go | 2 | ||||
-rw-r--r-- | internal/cmd/web.go | 9 | ||||
-rw-r--r-- | internal/context/context.go | 16 | ||||
-rw-r--r-- | internal/route/api/v1/repo/file.go | 6 | ||||
-rw-r--r-- | internal/route/repo/download.go | 13 | ||||
-rw-r--r-- | templates/.VERSION | 2 |
6 files changed, 26 insertions, 22 deletions
@@ -16,7 +16,7 @@ import ( "gogs.io/gogs/internal/setting" ) -const Version = "0.11.95.1024" +const Version = "0.11.96.1024" func init() { setting.AppVer = Version 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 } }) diff --git a/internal/context/context.go b/internal/context/context.go index 2bc4a4d0..49213177 100644 --- a/internal/context/context.go +++ b/internal/context/context.go @@ -167,13 +167,13 @@ func (c *Context) RenderWithErr(msg, tpl string, f interface{}) { } // Handle handles and logs error by given status. -func (c *Context) Handle(status int, title string, err error) { +func (c *Context) Handle(status int, msg string, err error) { switch status { case http.StatusNotFound: c.Data["Title"] = "Page Not Found" case http.StatusInternalServerError: c.Data["Title"] = "Internal Server Error" - log.Error(3, "%s: %v", title, err) + log.Error(3, "%s: %v", msg, err) if !setting.ProdMode || (c.IsLogged && c.User.IsAdmin) { c.Data["ErrorMsg"] = err } @@ -187,23 +187,23 @@ func (c *Context) NotFound() { } // ServerError renders the 500 page. -func (c *Context) ServerError(title string, err error) { - c.Handle(http.StatusInternalServerError, title, err) +func (c *Context) ServerError(msg string, err error) { + c.Handle(http.StatusInternalServerError, msg, err) } // NotFoundOrServerError use error check function to determine if the error // is about not found. It responses with 404 status code for not found error, // or error context description for logging purpose of 500 server error. -func (c *Context) NotFoundOrServerError(title string, errck func(error) bool, err error) { +func (c *Context) NotFoundOrServerError(msg string, errck func(error) bool, err error) { if errck(err) { c.NotFound() return } - c.ServerError(title, err) + c.ServerError(msg, err) } -func (c *Context) HandleText(status int, title string) { - c.PlainText(status, []byte(title)) +func (c *Context) HandleText(status int, msg string) { + c.PlainText(status, []byte(msg)) } func (c *Context) ServeContent(name string, r io.ReadSeeker, params ...interface{}) { diff --git a/internal/route/api/v1/repo/file.go b/internal/route/api/v1/repo/file.go index 4dcae313..47907af7 100644 --- a/internal/route/api/v1/repo/file.go +++ b/internal/route/api/v1/repo/file.go @@ -6,10 +6,10 @@ package repo import ( "github.com/gogs/git-module" - repo2 "gogs.io/gogs/internal/route/repo" "gogs.io/gogs/internal/context" "gogs.io/gogs/internal/db" + "gogs.io/gogs/internal/route/repo" ) func GetRawFile(c *context.APIContext) { @@ -28,7 +28,7 @@ func GetRawFile(c *context.APIContext) { c.NotFoundOrServerError("GetBlobByPath", git.IsErrNotExist, err) return } - if err = repo2.ServeBlob(c.Context, blob); err != nil { + if err = repo.ServeBlob(c.Context, blob); err != nil { c.ServerError("ServeBlob", err) } } @@ -42,7 +42,7 @@ func GetArchive(c *context.APIContext) { } c.Repo.GitRepo = gitRepo - repo2.Download(c.Context) + repo.Download(c.Context) } func GetEditorconfig(c *context.APIContext) { 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) { diff --git a/templates/.VERSION b/templates/.VERSION index 8d399722..b2eef69b 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.11.95.1024 +0.11.96.1024 |