From 9249c015eff3f264566e29fd999c7f500c4988f5 Mon Sep 17 00:00:00 2001 From: Lian Date: Sat, 22 Jan 2022 11:29:24 -0500 Subject: [PATCH] enable download for app.Static --- app.go | 4 ++++ router.go | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/app.go b/app.go index 9abd4e9dbf1..9d5290640a6 100644 --- a/app.go +++ b/app.go @@ -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"` diff --git a/router.go b/router.go index 687e8fd578c..74a8fe75840 100644 --- a/router.go +++ b/router.go @@ -375,6 +375,10 @@ func (app *App) registerStatic(prefix, root string, config ...Static) Router { } // Serve file fileHandler(c.fasthttp) + // sets the HTTP response Content-Disposition header to attachment if config Download 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 {