Skip to content

Commit

Permalink
enable download for app.Static
Browse files Browse the repository at this point in the history
wording
  • Loading branch information
Lian1230 committed Jan 22, 2022
1 parent d59f1af commit 9570adc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app.go
Expand Up @@ -374,6 +374,10 @@ type Static struct {
// Optional. Default value false.
Browse bool `json:"browse"`

// When set to true, enables direct download.
// Optional. Default value false.
Download bool `json:"download"`

// The name of the index file for serving a directory.
// Optional. Default value "index.html".
Index string `json:"index"`
Expand Down
4 changes: 4 additions & 0 deletions router.go
Expand Up @@ -375,6 +375,10 @@ func (app *App) registerStatic(prefix, root string, config ...Static) Router {
}
// Serve file
fileHandler(c.fasthttp)
// Sets the response Content-Disposition header to attachment if the Download option is true
if len(config) > 0 && config[0].Download {
c.Attachment()
}
// Return request if found and not forbidden
status := c.fasthttp.Response.StatusCode()
if status != StatusNotFound && status != StatusForbidden {
Expand Down

0 comments on commit 9570adc

Please sign in to comment.