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, "