Skip to content

Commit 34cd13e

Browse files
authored
response: clarify Content-Disposition, close file in Stream example (#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`.
1 parent a2569cd commit 34cd13e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

website/docs/guide/response.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ func(c echo.Context) error {
244244
## Send Attachment
245245

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

249249
*Example*
250250

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

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

262262
*Example*
263263

@@ -296,6 +296,7 @@ func(c echo.Context) error {
296296
if err != nil {
297297
return err
298298
}
299+
defer f.Close()
299300
return c.Stream(http.StatusOK, "image/png", f)
300301
}
301302
```

0 commit comments

Comments
 (0)