Skip to content

Commit

Permalink
Return error of context.File in c.contentDisposition
Browse files Browse the repository at this point in the history
context.Attachment and context.Inline use context.contentDisposition under the hood.
However, context.contentDisposition does not forward the error of context.File, leading to response 200 OK even when the file does not exist.
This commit forward the return value of context.File to context.contentDisposition to prevent that.
  • Loading branch information
acristal authored and vishr committed Mar 6, 2018
1 parent 9b9f4fa commit fb30777
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,18 +509,17 @@ func (c *context) File(file string) (err error) {
return
}

func (c *context) Attachment(file, name string) (err error) {
func (c *context) Attachment(file, name string) error {
return c.contentDisposition(file, name, "attachment")
}

func (c *context) Inline(file, name string) (err error) {
func (c *context) Inline(file, name string) error {
return c.contentDisposition(file, name, "inline")
}

func (c *context) contentDisposition(file, name, dispositionType string) (err error) {
func (c *context) contentDisposition(file, name, dispositionType string) error {
c.response.Header().Set(HeaderContentDisposition, fmt.Sprintf("%s; filename=%q", dispositionType, name))
c.File(file)
return
return c.File(file)
}

func (c *context) NoContent(code int) error {
Expand Down

0 comments on commit fb30777

Please sign in to comment.