Skip to content

Commit

Permalink
response: clarify Content-Disposition, close file in Stream example (#…
Browse files Browse the repository at this point in the history
…351)

It wasn't clear to me what were the differences between `Context#File`,
`Context#Attachment` and `Context#Inline` - reading the source made it
clearer: the former 2 are referring to sending `Content-Disposition`
with `attachment` and `inline`, which makes sense.

Adding missing `defer f.Close()` in the `Context#Stream` example. I also
checked, it takes an `io.Reader` not an `io.ReadCloser` so it couldn't
delegate the close to `Context#Stream`.
  • Loading branch information
StalkR authored Oct 3, 2024
1 parent a2569cd commit 34cd13e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions website/docs/guide/response.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func(c echo.Context) error {
## Send Attachment

`Context#Attachment(file, name string)` is similar to `File()` except that it is
used to send file as attachment with provided name.
used to send file as `Content-Disposition: attachment` with provided name.

*Example*

Expand All @@ -257,7 +257,7 @@ func(c echo.Context) error {
## Send Inline

`Context#Inline(file, name string)` is similar to `File()` except that it is
used to send file as inline with provided name.
used to send file as `Content-Disposition: inline` with provided name.

*Example*

Expand Down Expand Up @@ -296,6 +296,7 @@ func(c echo.Context) error {
if err != nil {
return err
}
defer f.Close()
return c.Stream(http.StatusOK, "image/png", f)
}
```
Expand Down

0 comments on commit 34cd13e

Please sign in to comment.