diff --git a/.github/README.md b/.github/README.md index 3ffe71d55be..64bc6e37f12 100644 --- a/.github/README.md +++ b/.github/README.md @@ -604,6 +604,7 @@ This is a list of middlewares that are created by the Fiber community, please cr - [theArtechnology/fiber-inertia](https://github.com/theArtechnology/fiber-inertia) - [aschenmaker/fiber-health-check](https://github.com/aschenmaker/fiber-health-check) - [elastic/apmfiber](https://github.com/elastic/apm-agent-go/tree/master/module/apmfiber) +- [eozer/fiber_ldapauth](https://github.com/eozer/fiber_ldapauth) ## 👍 Contribute diff --git a/.github/README_ckb.md b/.github/README_ckb.md index 0cceafa7d41..4b12e914e4a 100644 --- a/.github/README_ckb.md +++ b/.github/README_ckb.md @@ -604,6 +604,7 @@ func main() { - [theArtechnology/fiber-inertia](https://github.com/theArtechnology/fiber-inertia) - [aschenmaker/fiber-health-check](https://github.com/aschenmaker/fiber-health-check) - [elastic/apmfiber](https://github.com/elastic/apm-agent-go/tree/master/module/apmfiber) +- [eozer/fiber_ldapauth](https://github.com/eozer/fiber_ldapauth) ## 👍 هاوکار بە diff --git a/.github/README_de.md b/.github/README_de.md index 517349462ad..9f3dd5587ec 100644 --- a/.github/README_de.md +++ b/.github/README_de.md @@ -574,6 +574,7 @@ This is a list of middlewares that are created by the Fiber community, please cr - [theArtechnology/fiber-inertia](https://github.com/theArtechnology/fiber-inertia) - [aschenmaker/fiber-health-check](https://github.com/aschenmaker/fiber-health-check) - [elastic/apmfiber](https://github.com/elastic/apm-agent-go/tree/master/module/apmfiber) +- [eozer/fiber_ldapauth](https://github.com/eozer/fiber_ldapauth) ## 👍 Mitwirken diff --git a/.github/README_es.md b/.github/README_es.md index e753e8bca94..c50e524b0c8 100644 --- a/.github/README_es.md +++ b/.github/README_es.md @@ -574,6 +574,7 @@ La siguiente es una lista de los proyectos de middleware creados por la comunida - [theArtechnology/fiber-inertia](https://github.com/theArtechnology/fiber-inertia) - [aschenmaker/fiber-health-check](https://github.com/aschenmaker/fiber-health-check) - [elastic/apmfiber](https://github.com/elastic/apm-agent-go/tree/master/module/apmfiber) +- [eozer/fiber_ldapauth](https://github.com/eozer/fiber_ldapauth) ## 👍 Contribuir diff --git a/.github/README_fa.md b/.github/README_fa.md index 81129bd3bd9..ad2ddbbadde 100644 --- a/.github/README_fa.md +++ b/.github/README_fa.md @@ -705,6 +705,7 @@ Middleware های لیست زیر توسط انجمن Fiber ایجاد است, - [theArtechnology/fiber-inertia](https://github.com/theArtechnology/fiber-inertia) - [aschenmaker/fiber-health-check](https://github.com/aschenmaker/fiber-health-check) - [elastic/apmfiber](https://github.com/elastic/apm-agent-go/tree/master/module/apmfiber) +- [eozer/fiber_ldapauth](https://github.com/eozer/fiber_ldapauth)
diff --git a/.github/README_fr.md b/.github/README_fr.md index 7e47f6b8dd6..0dcc691089e 100644 --- a/.github/README_fr.md +++ b/.github/README_fr.md @@ -576,6 +576,7 @@ This is a list of middlewares that are created by the Fiber community, please cr - [theArtechnology/fiber-inertia](https://github.com/theArtechnology/fiber-inertia) - [aschenmaker/fiber-health-check](https://github.com/aschenmaker/fiber-health-check) - [elastic/apmfiber](https://github.com/elastic/apm-agent-go/tree/master/module/apmfiber) +- [eozer/fiber_ldapauth](https://github.com/eozer/fiber_ldapauth) ## 👍 Contribuer diff --git a/.github/README_he.md b/.github/README_he.md index f65aac435e4..6708d6fcaec 100644 --- a/.github/README_he.md +++ b/.github/README_he.md @@ -710,6 +710,7 @@ This is a list of middlewares that are created by the Fiber community, please cr - [theArtechnology/fiber-inertia](https://github.com/theArtechnology/fiber-inertia) - [aschenmaker/fiber-health-check](https://github.com/aschenmaker/fiber-health-check) - [elastic/apmfiber](https://github.com/elastic/apm-agent-go/tree/master/module/apmfiber) +- [eozer/fiber_ldapauth](https://github.com/eozer/fiber_ldapauth) diff --git a/.github/README_id.md b/.github/README_id.md index 82648f9ca75..e83ceee61b8 100644 --- a/.github/README_id.md +++ b/.github/README_id.md @@ -577,6 +577,7 @@ Berikut adalah kumpulan _middlewares_ yang dibuat oleh komunitas Fiber, silahkan - [theArtechnology/fiber-inertia](https://github.com/theArtechnology/fiber-inertia) - [aschenmaker/fiber-health-check](https://github.com/aschenmaker/fiber-health-check) - [elastic/apmfiber](https://github.com/elastic/apm-agent-go/tree/master/module/apmfiber) +- [eozer/fiber_ldapauth](https://github.com/eozer/fiber_ldapauth) ## 👍 Berkontribusi diff --git a/.github/README_it.md b/.github/README_it.md index ca3c3996b62..a752de5455a 100644 --- a/.github/README_it.md +++ b/.github/README_it.md @@ -600,6 +600,7 @@ Questa è una lista dei middleware che sono stati creati dalla comunità di Fibe - [theArtechnology/fiber-inertia](https://github.com/theArtechnology/fiber-inertia) - [aschenmaker/fiber-health-check](https://github.com/aschenmaker/fiber-health-check) - [elastic/apmfiber](https://github.com/elastic/apm-agent-go/tree/master/module/apmfiber) +- [eozer/fiber_ldapauth](https://github.com/eozer/fiber_ldapauth) ## 👍 Contribuire diff --git a/.github/README_ja.md b/.github/README_ja.md index 6c9277dfa29..68d4bcd4bcb 100644 --- a/.github/README_ja.md +++ b/.github/README_ja.md @@ -580,6 +580,7 @@ This is a list of middlewares that are created by the Fiber community, please cr - [theArtechnology/fiber-inertia](https://github.com/theArtechnology/fiber-inertia) - [aschenmaker/fiber-health-check](https://github.com/aschenmaker/fiber-health-check) - [elastic/apmfiber](https://github.com/elastic/apm-agent-go/tree/master/module/apmfiber) +- [eozer/fiber_ldapauth](https://github.com/eozer/fiber_ldapauth) ## 👍 貢献する diff --git a/.github/README_ko.md b/.github/README_ko.md index addae78ac9c..ddc6c07a8c7 100644 --- a/.github/README_ko.md +++ b/.github/README_ko.md @@ -580,6 +580,7 @@ Fiber 프레임워크에 포함되는 미들웨어 목록입니다. - [theArtechnology/fiber-inertia](https://github.com/theArtechnology/fiber-inertia) - [aschenmaker/fiber-health-check](https://github.com/aschenmaker/fiber-health-check) - [elastic/apmfiber](https://github.com/elastic/apm-agent-go/tree/master/module/apmfiber) +- [eozer/fiber_ldapauth](https://github.com/eozer/fiber_ldapauth) ## 👍 기여 diff --git a/.github/README_nl.md b/.github/README_nl.md index 2a7b21ed71d..a52f32d916f 100644 --- a/.github/README_nl.md +++ b/.github/README_nl.md @@ -580,6 +580,7 @@ This is a list of middlewares that are created by the Fiber community, please cr - [theArtechnology/fiber-inertia](https://github.com/theArtechnology/fiber-inertia) - [aschenmaker/fiber-health-check](https://github.com/aschenmaker/fiber-health-check) - [elastic/apmfiber](https://github.com/elastic/apm-agent-go/tree/master/module/apmfiber) +- [eozer/fiber_ldapauth](https://github.com/eozer/fiber_ldapauth) ## 👍 Bijdragen diff --git a/.github/README_pt.md b/.github/README_pt.md index 60143741c5b..3e818406a22 100644 --- a/.github/README_pt.md +++ b/.github/README_pt.md @@ -574,6 +574,7 @@ Esta é uma lista de middlewares criados pela comunidade do Fiber, se quiser ter - [theArtechnology/fiber-inertia](https://github.com/theArtechnology/fiber-inertia) - [aschenmaker/fiber-health-check](https://github.com/aschenmaker/fiber-health-check) - [elastic/apmfiber](https://github.com/elastic/apm-agent-go/tree/master/module/apmfiber) +- [eozer/fiber_ldapauth](https://github.com/eozer/fiber_ldapauth) ## 👍 Contribuindo diff --git a/.github/README_ru.md b/.github/README_ru.md index a17b5e39f45..eee845895c1 100644 --- a/.github/README_ru.md +++ b/.github/README_ru.md @@ -581,6 +581,7 @@ func main() { - [theArtechnology/fiber-inertia](https://github.com/theArtechnology/fiber-inertia) - [aschenmaker/fiber-health-check](https://github.com/aschenmaker/fiber-health-check) - [elastic/apmfiber](https://github.com/elastic/apm-agent-go/tree/master/module/apmfiber) +- [eozer/fiber_ldapauth](https://github.com/eozer/fiber_ldapauth) ## 👍 Помощь проекту diff --git a/.github/README_sa.md b/.github/README_sa.md index 39729ee4d17..4518eea3829 100644 --- a/.github/README_sa.md +++ b/.github/README_sa.md @@ -641,6 +641,7 @@ List of externally hosted middleware modules and maintained by the [Fiber team]( - [theArtechnology/fiber-inertia](https://github.com/theArtechnology/fiber-inertia) - [aschenmaker/fiber-health-check](https://github.com/aschenmaker/fiber-health-check) - [elastic/apmfiber](https://github.com/elastic/apm-agent-go/tree/master/module/apmfiber) +- [eozer/fiber_ldapauth](https://github.com/eozer/fiber_ldapauth) ## 👍 مساهمة diff --git a/.github/README_tr.md b/.github/README_tr.md index 2d6dd228152..ba10a4cc9ca 100644 --- a/.github/README_tr.md +++ b/.github/README_tr.md @@ -574,6 +574,7 @@ Bu, Fiber topluluğu tarafından oluşturulan middleware'lerin bir listesidir, s - [theArtechnology/fiber-inertia](https://github.com/theArtechnology/fiber-inertia) - [aschenmaker/fiber-health-check](https://github.com/aschenmaker/fiber-health-check) - [elastic/apmfiber](https://github.com/elastic/apm-agent-go/tree/master/module/apmfiber) +- [eozer/fiber_ldapauth](https://github.com/eozer/fiber_ldapauth) ## 👍 Destek diff --git a/.github/README_zh-CN.md b/.github/README_zh-CN.md index 18db31a757a..d54c56149ca 100644 --- a/.github/README_zh-CN.md +++ b/.github/README_zh-CN.md @@ -576,6 +576,7 @@ func main() { - [theArtechnology/fiber-inertia](https://github.com/theArtechnology/fiber-inertia) - [aschenmaker/fiber-health-check](https://github.com/aschenmaker/fiber-health-check) - [elastic/apmfiber](https://github.com/elastic/apm-agent-go/tree/master/module/apmfiber) +- [eozer/fiber_ldapauth](https://github.com/eozer/fiber_ldapauth) ## 👍 贡献 diff --git a/.github/README_zh-TW.md b/.github/README_zh-TW.md index 720d9d4906b..5d8c8ba93c3 100644 --- a/.github/README_zh-TW.md +++ b/.github/README_zh-TW.md @@ -574,6 +574,7 @@ func main() { - [theArtechnology/fiber-inertia](https://github.com/theArtechnology/fiber-inertia) - [aschenmaker/fiber-health-check](https://github.com/aschenmaker/fiber-health-check) - [elastic/apmfiber](https://github.com/elastic/apm-agent-go/tree/master/module/apmfiber) +- [eozer/fiber_ldapauth](https://github.com/eozer/fiber_ldapauth) ## 👍 貢獻 diff --git a/app.go b/app.go index fb2d2587ca0..17ca68d1066 100644 --- a/app.go +++ b/app.go @@ -36,7 +36,7 @@ import ( ) // Version of current fiber package -const Version = "2.25.0" +const Version = "2.26.0" // Handler defines a function to serve HTTP requests. type Handler = func(*Ctx) error @@ -359,7 +359,7 @@ type Config struct { trustedProxiesMap map[string]struct{} trustedProxyRanges []*net.IPNet - //If set to true, will print all routes with their method, path and handler. + // If set to true, will print all routes with their method, path and handler. // Default: false EnablePrintRoutes bool `json:"enable_print_routes"` } @@ -379,6 +379,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/app_test.go b/app_test.go index 5c17866e5db..a9ec4d01da4 100644 --- a/app_test.go +++ b/app_test.go @@ -678,6 +678,22 @@ func Test_App_Static_MaxAge(t *testing.T) { utils.AssertEqual(t, "public, max-age=100", resp.Header.Get(HeaderCacheControl), "CacheControl Control") } +// go test -run Test_App_Static_Download +func Test_App_Static_Download(t *testing.T) { + app := New() + c := app.AcquireCtx(&fasthttp.RequestCtx{}) + defer app.ReleaseCtx(c) + + app.Static("/fiber.png", "./.github/testdata/fs/img/fiber.png", Static{Download: true}) + + resp, err := app.Test(httptest.NewRequest("GET", "/fiber.png", nil)) + utils.AssertEqual(t, nil, err, "app.Test(req)") + utils.AssertEqual(t, 200, resp.StatusCode, "Status code") + utils.AssertEqual(t, false, resp.Header.Get(HeaderContentLength) == "") + utils.AssertEqual(t, "image/png", resp.Header.Get(HeaderContentType)) + utils.AssertEqual(t, `attachment`, resp.Header.Get(HeaderContentDisposition)) +} + // go test -run Test_App_Static_Group func Test_App_Static_Group(t *testing.T) { app := New() diff --git a/ctx.go b/ctx.go index af2032ac080..ab1a9eaa333 100644 --- a/ctx.go +++ b/ctx.go @@ -11,6 +11,7 @@ import ( "errors" "fmt" "io" + "io/ioutil" "mime/multipart" "net" "net/http" @@ -782,6 +783,14 @@ func (c *Ctx) Next() (err error) { return err } +// RestartRouting instead of going to the next handler. This may be usefull after +// changing the request path. Note that handlers might be executed again. +func (c *Ctx) RestartRouting() error { + c.indexRoute = -1 + _, err := c.app.next(c) + return err +} + // OriginalURL contains the original request URL. // Returned value is only valid within the handler. Do not store any references. // Make copies or use the Immutable setting to use the value outside the Handler. @@ -1128,6 +1137,21 @@ func (c *Ctx) SaveFile(fileheader *multipart.FileHeader, path string) error { return fasthttp.SaveMultipartFile(fileheader, path) } +// SaveFileToStorage saves any multipart file to an external storage system. +func (c *Ctx) SaveFileToStorage(fileheader *multipart.FileHeader, path string, storage Storage) error { + file, err := fileheader.Open() + if err != nil { + return err + } + + content, err := ioutil.ReadAll(file) + if err != nil { + return err + } + + return storage.Set(path, content, 0) +} + // Secure returns a boolean property, that is true, if a TLS connection is established. func (c *Ctx) Secure() bool { return c.fasthttp.IsTLS() diff --git a/ctx_test.go b/ctx_test.go index f5149dbb02d..1e857143b8e 100644 --- a/ctx_test.go +++ b/ctx_test.go @@ -27,6 +27,7 @@ import ( "time" "github.com/gofiber/fiber/v2/internal/bytebufferpool" + "github.com/gofiber/fiber/v2/internal/storage/memory" "github.com/gofiber/fiber/v2/utils" "github.com/valyala/fasthttp" ) @@ -1614,6 +1615,48 @@ func Test_Ctx_SaveFile(t *testing.T) { utils.AssertEqual(t, StatusOK, resp.StatusCode, "Status code") } +// go test -run Test_Ctx_SaveFileToStorage +func Test_Ctx_SaveFileToStorage(t *testing.T) { + t.Parallel() + app := New() + storage := memory.New() + + app.Post("/test", func(c *Ctx) error { + fh, err := c.FormFile("file") + utils.AssertEqual(t, nil, err) + + err = c.SaveFileToStorage(fh, "test", storage) + utils.AssertEqual(t, nil, err) + + file, err := storage.Get("test") + utils.AssertEqual(t, []byte("hello world"), file) + utils.AssertEqual(t, nil, err) + + err = storage.Delete("test") + utils.AssertEqual(t, nil, err) + + return nil + }) + + body := &bytes.Buffer{} + writer := multipart.NewWriter(body) + + ioWriter, err := writer.CreateFormFile("file", "test") + utils.AssertEqual(t, nil, err) + + _, err = ioWriter.Write([]byte("hello world")) + utils.AssertEqual(t, nil, err) + writer.Close() + + req := httptest.NewRequest(MethodPost, "/test", body) + req.Header.Set("Content-Type", writer.FormDataContentType()) + req.Header.Set("Content-Length", strconv.Itoa(len(body.Bytes()))) + + resp, err := app.Test(req) + utils.AssertEqual(t, nil, err, "app.Test(req)") + utils.AssertEqual(t, StatusOK, resp.StatusCode, "Status code") +} + // go test -run Test_Ctx_Secure func Test_Ctx_Secure(t *testing.T) { t.Parallel() @@ -2065,6 +2108,69 @@ func Test_Ctx_RenderWithLocalsAndBinding(t *testing.T) { utils.AssertEqual(t, "

Hello, World!

", string(c.Response().Body())) } +// go test -run Test_Ctx_RestartRouting +func Test_Ctx_RestartRouting(t *testing.T) { + app := New() + calls := 0 + app.Get("/", func(c *Ctx) error { + calls++ + if calls < 3 { + return c.RestartRouting() + } + return nil + }) + resp, err := app.Test(httptest.NewRequest(MethodGet, "http://example.com/", nil)) + utils.AssertEqual(t, nil, err, "app.Test(req)") + utils.AssertEqual(t, StatusOK, resp.StatusCode, "Status code") + utils.AssertEqual(t, 3, calls, "Number of calls") +} + +// go test -run Test_Ctx_RestartRoutingWithChangedPath +func Test_Ctx_RestartRoutingWithChangedPath(t *testing.T) { + app := New() + executedOldHandler := false + executedNewHandler := false + + app.Get("/old", func(c *Ctx) error { + c.Path("/new") + return c.RestartRouting() + }) + app.Get("/old", func(c *Ctx) error { + executedOldHandler = true + return nil + }) + app.Get("/new", func(c *Ctx) error { + executedNewHandler = true + return nil + }) + + resp, err := app.Test(httptest.NewRequest(MethodGet, "http://example.com/old", nil)) + utils.AssertEqual(t, nil, err, "app.Test(req)") + utils.AssertEqual(t, StatusOK, resp.StatusCode, "Status code") + utils.AssertEqual(t, false, executedOldHandler, "Executed old handler") + utils.AssertEqual(t, true, executedNewHandler, "Executed new handler") +} + +// go test -run Test_Ctx_RestartRoutingWithChangedPathAnd404 +func Test_Ctx_RestartRoutingWithChangedPathAndCatchAll(t *testing.T) { + app := New() + app.Get("/new", func(c *Ctx) error { + return nil + }) + app.Use(func(c *Ctx) error { + c.Path("/new") + // c.Next() would fail this test as a 404 is returned from the next handler + return c.RestartRouting() + }) + app.Use(func(c *Ctx) error { + return ErrNotFound + }) + + resp, err := app.Test(httptest.NewRequest(MethodGet, "http://example.com/old", nil)) + utils.AssertEqual(t, nil, err, "app.Test(req)") + utils.AssertEqual(t, StatusOK, resp.StatusCode, "Status code") +} + type testTemplateEngine struct { templates *template.Template } diff --git a/go.mod b/go.mod index a676731cd09..4e2f97572f3 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,6 @@ module github.com/gofiber/fiber/v2 go 1.16 require ( - github.com/valyala/fasthttp v1.32.0 - golang.org/x/sys v0.0.0-20210514084401-e8d321eab015 + github.com/valyala/fasthttp v1.33.0 + golang.org/x/sys v0.0.0-20220111092808-5a964db01320 ) diff --git a/go.sum b/go.sum index e77d494f835..67e5a03ee74 100644 --- a/go.sum +++ b/go.sum @@ -1,22 +1,22 @@ -github.com/andybalholm/brotli v1.0.2 h1:JKnhI/XQ75uFBTiuzXpzFrUriDPiZjlOSzh6wXogP0E= -github.com/andybalholm/brotli v1.0.2/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y= -github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/klauspost/compress v1.13.4 h1:0zhec2I8zGnjWcKyLl6i3gPqKANCCn5e9xmviEEeX6s= -github.com/klauspost/compress v1.13.4/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg= +github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY= +github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= +github.com/klauspost/compress v1.14.1 h1:hLQYb23E8/fO+1u53d02A97a8UnsddcvYzq4ERRU4ds= +github.com/klauspost/compress v1.14.1/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= -github.com/valyala/fasthttp v1.32.0 h1:keswgWzyKyNIIjz2a7JmCYHOOIkRp6HMx9oTV6QrZWY= -github.com/valyala/fasthttp v1.32.0/go.mod h1:2rsYD01CKFrjjsvFxx75KlEUNpWNBY9JWD3K/7o2Cus= +github.com/valyala/fasthttp v1.33.0 h1:mHBKd98J5NcXuBddgjvim1i3kWzlng1SzLhrnBOU9g8= +github.com/valyala/fasthttp v1.33.0/go.mod h1:KJRK/MXx0J+yd0c5hlR+s1tIHD72sniU8ZJjl97LIw4= github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8= github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= -golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20210510120150-4163338589ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220111093109-d55c255bac03/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210514084401-e8d321eab015 h1:hZR0X1kPW+nwyJ9xRxqZk1vx5RUObAPBdKVvXPDUH/E= -golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220111092808-5a964db01320 h1:0jf+tOCoZ3LyutmCOWpVni1chK4VfFLhRsDK7MhqGRY= +golang.org/x/sys v0.0.0-20220111092808-5a964db01320/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/router.go b/router.go index cc88299ea16..4190771bcf7 100644 --- a/router.go +++ b/router.go @@ -377,6 +377,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 {