github.com/gofiber/fiber/v2
Advanced tools
+1
-1
@@ -33,3 +33,3 @@ // ⚡️ Fiber is an Express inspired web framework written in Go with ☕️ | ||
| // Version of current fiber package | ||
| const Version = "2.52.8" | ||
| const Version = "2.52.9" | ||
@@ -36,0 +36,0 @@ // Handler defines a function to serve HTTP requests. |
+9
-7
@@ -397,3 +397,3 @@ // ⚡️ Fiber is an Express inspired web framework written in Go with ☕️ | ||
| } | ||
| if strings.HasPrefix(ctype, MIMEApplicationForm) { | ||
| if ctype == MIMEApplicationForm { | ||
| data := make(map[string][]string) | ||
@@ -419,3 +419,3 @@ var err error | ||
| } | ||
| if strings.HasPrefix(ctype, MIMEMultipartForm) { | ||
| if ctype == MIMEMultipartForm { | ||
| multipartForm, err := c.fasthttp.MultipartForm() | ||
@@ -436,3 +436,3 @@ if err != nil { | ||
| } | ||
| if strings.HasPrefix(ctype, MIMETextXML) || strings.HasPrefix(ctype, MIMEApplicationXML) { | ||
| if ctype == MIMETextXML || ctype == MIMEApplicationXML { | ||
| if err := xml.Unmarshal(c.Body(), out); err != nil { | ||
@@ -883,6 +883,8 @@ return fmt.Errorf("failed to unmarshal: %w", err) | ||
| return strings.HasPrefix( | ||
| utils.TrimLeft(c.app.getString(c.fasthttp.Request.Header.ContentType()), ' '), | ||
| extensionHeader, | ||
| ) | ||
| ct := c.app.getString(c.fasthttp.Request.Header.ContentType()) | ||
| if i := strings.IndexByte(ct, ';'); i != -1 { | ||
| ct = ct[:i] | ||
| } | ||
| ct = utils.Trim(ct, ' ') | ||
| return utils.EqualFold(ct, extensionHeader) | ||
| } | ||
@@ -889,0 +891,0 @@ |
@@ -15,4 +15,9 @@ // Copyright 2012 The Gorilla Authors. All rights reserved. | ||
| var errInvalidPath = errors.New("schema: invalid path") | ||
| const maxParserIndex = 1000 | ||
| var ( | ||
| errInvalidPath = errors.New("schema: invalid path") | ||
| errIndexTooLarge = errors.New("schema: index exceeds parser limit") | ||
| ) | ||
| // newCache returns a new cache. | ||
@@ -81,2 +86,5 @@ func newCache() *cache { | ||
| } | ||
| if index64 > maxParserIndex { | ||
| return nil, errIndexTooLarge | ||
| } | ||
| parts = append(parts, pathPart{ | ||
@@ -83,0 +91,0 @@ path: path, |
@@ -96,4 +96,8 @@ // Copyright 2012 The Gorilla Authors. All rights reserved. | ||
| } | ||
| } else if !d.ignoreUnknownKeys { | ||
| multiError[path] = UnknownKeyError{Key: path} | ||
| } else { | ||
| if errors.Is(err, errIndexTooLarge) { | ||
| multiError[path] = err | ||
| } else if !d.ignoreUnknownKeys { | ||
| multiError[path] = UnknownKeyError{Key: path} | ||
| } | ||
| } | ||
@@ -100,0 +104,0 @@ } |
@@ -20,21 +20,56 @@ package proxy | ||
| func createProxyTestServer(t *testing.T, handler fiber.Handler) (*fiber.App, string) { | ||
| func startServer(t *testing.T, app *fiber.App, ln net.Listener) { | ||
| t.Helper() | ||
| go func() { | ||
| utils.AssertEqual(t, nil, app.Listener(ln)) | ||
| }() | ||
| time.Sleep(200 * time.Millisecond) | ||
| } | ||
| target := fiber.New(fiber.Config{DisableStartupMessage: true}) | ||
| func createProxyTestServer(t *testing.T, handler fiber.Handler, network, address string) (*fiber.App, string) { | ||
| t.Helper() | ||
| target := fiber.New() | ||
| target.Get("/", handler) | ||
| ln, err := net.Listen(fiber.NetworkTCP4, "127.0.0.1:0") | ||
| ln, err := net.Listen(network, address) | ||
| utils.AssertEqual(t, nil, err) | ||
| go func() { | ||
| utils.AssertEqual(t, nil, target.Listener(ln)) | ||
| }() | ||
| time.Sleep(2 * time.Second) | ||
| addr := ln.Addr().String() | ||
| startServer(t, target, ln) | ||
| return target, addr | ||
| } | ||
| func createProxyTestServerIPv4(t *testing.T, handler fiber.Handler) (*fiber.App, string) { | ||
| t.Helper() | ||
| return createProxyTestServer(t, handler, fiber.NetworkTCP4, "127.0.0.1:0") | ||
| } | ||
| // createRedirectServer creates a simple redirecting server used in tests. | ||
| // | ||
| //nolint:unparam // this is only for testing | ||
| func createRedirectServer(t *testing.T) (*fiber.App, string) { | ||
| t.Helper() | ||
| app := fiber.New() | ||
| var addr string | ||
| app.Get("/", func(c *fiber.Ctx) error { | ||
| c.Location("http://" + addr + "/final") | ||
| return c.Status(fiber.StatusMovedPermanently).SendString("redirect") | ||
| }) | ||
| app.Get("/final", func(c *fiber.Ctx) error { | ||
| return c.SendString("final") | ||
| }) | ||
| ln, err := net.Listen(fiber.NetworkTCP4, "127.0.0.1:0") | ||
| utils.AssertEqual(t, nil, err) | ||
| addr = ln.Addr().String() | ||
| startServer(t, app, ln) | ||
| return app, addr | ||
| } | ||
| // go test -run Test_Proxy_Empty_Host | ||
@@ -87,3 +122,3 @@ func Test_Proxy_Empty_Upstream_Servers(t *testing.T) { | ||
| target, addr := createProxyTestServer(t, func(c *fiber.Ctx) error { | ||
| target, addr := createProxyTestServerIPv4(t, func(c *fiber.Ctx) error { | ||
| return c.SendStatus(fiber.StatusTeapot) | ||
@@ -147,3 +182,3 @@ }) | ||
| _, targetAddr := createProxyTestServer(t, func(c *fiber.Ctx) error { | ||
| _, targetAddr := createProxyTestServerIPv4(t, func(c *fiber.Ctx) error { | ||
| return c.SendString("hello from target") | ||
@@ -184,3 +219,3 @@ }) | ||
| _, addr := createProxyTestServer(t, func(c *fiber.Ctx) error { | ||
| _, addr := createProxyTestServerIPv4(t, func(c *fiber.Ctx) error { | ||
| return c.SendString("forwarded") | ||
@@ -238,3 +273,3 @@ }) | ||
| _, addr := createProxyTestServer(t, func(c *fiber.Ctx) error { | ||
| _, addr := createProxyTestServerIPv4(t, func(c *fiber.Ctx) error { | ||
| return c.Status(500).SendString("not modified") | ||
@@ -265,3 +300,3 @@ }) | ||
| _, addr := createProxyTestServer(t, func(c *fiber.Ctx) error { | ||
| _, addr := createProxyTestServerIPv4(t, func(c *fiber.Ctx) error { | ||
| b := c.Request().Body() | ||
@@ -293,3 +328,3 @@ return c.SendString(string(b)) | ||
| _, addr := createProxyTestServer(t, func(c *fiber.Ctx) error { | ||
| _, addr := createProxyTestServerIPv4(t, func(c *fiber.Ctx) error { | ||
| time.Sleep(2 * time.Second) | ||
@@ -318,3 +353,3 @@ return c.SendString("fiber is awesome") | ||
| _, addr := createProxyTestServer(t, func(c *fiber.Ctx) error { | ||
| _, addr := createProxyTestServerIPv4(t, func(c *fiber.Ctx) error { | ||
| time.Sleep(1 * time.Second) | ||
@@ -343,3 +378,3 @@ return c.SendString("fiber is awesome") | ||
| _, addr := createProxyTestServer(t, func(c *fiber.Ctx) error { | ||
| _, addr := createProxyTestServerIPv4(t, func(c *fiber.Ctx) error { | ||
| long := strings.Join(make([]string, 5000), "-") | ||
@@ -371,3 +406,3 @@ c.Set("Very-Long-Header", long) | ||
| t.Parallel() | ||
| _, addr := createProxyTestServer(t, func(c *fiber.Ctx) error { | ||
| _, addr := createProxyTestServerIPv4(t, func(c *fiber.Ctx) error { | ||
| return c.SendString("proxied") | ||
@@ -392,8 +427,13 @@ }) | ||
| t.Parallel() | ||
| _, addr := createProxyTestServerIPv4(t, func(c *fiber.Ctx) error { | ||
| return c.SendString("real url") | ||
| }) | ||
| app := fiber.New() | ||
| app.Get("/test", func(c *fiber.Ctx) error { | ||
| return Do(c, "https://www.google.com") | ||
| return Do(c, "http://"+addr) | ||
| }) | ||
| resp, err1 := app.Test(httptest.NewRequest(fiber.MethodGet, "/test", nil)) | ||
| resp, err1 := app.Test(httptest.NewRequest(fiber.MethodGet, "/test", nil), 2000) | ||
| utils.AssertEqual(t, nil, err1) | ||
@@ -404,3 +444,3 @@ utils.AssertEqual(t, fiber.StatusOK, resp.StatusCode) | ||
| utils.AssertEqual(t, nil, err) | ||
| utils.AssertEqual(t, true, strings.Contains(string(body), "https://www.google.com/")) | ||
| utils.AssertEqual(t, "real url", string(body)) | ||
| } | ||
@@ -411,13 +451,16 @@ | ||
| t.Parallel() | ||
| _, addr := createRedirectServer(t) | ||
| app := fiber.New() | ||
| app.Get("/test", func(c *fiber.Ctx) error { | ||
| return Do(c, "https://google.com") | ||
| return Do(c, "http://"+addr) | ||
| }) | ||
| resp, err1 := app.Test(httptest.NewRequest(fiber.MethodGet, "/test", nil)) | ||
| resp, err1 := app.Test(httptest.NewRequest(fiber.MethodGet, "/test", nil), 2000) | ||
| utils.AssertEqual(t, nil, err1) | ||
| body, err := io.ReadAll(resp.Body) | ||
| utils.AssertEqual(t, nil, err) | ||
| utils.AssertEqual(t, true, strings.Contains(string(body), "https://www.google.com/")) | ||
| utils.AssertEqual(t, 301, resp.StatusCode) | ||
| utils.AssertEqual(t, "redirect", string(body)) | ||
| utils.AssertEqual(t, fiber.StatusMovedPermanently, resp.StatusCode) | ||
| } | ||
@@ -428,11 +471,15 @@ | ||
| t.Parallel() | ||
| _, addr := createRedirectServer(t) | ||
| app := fiber.New() | ||
| app.Get("/test", func(c *fiber.Ctx) error { | ||
| return DoRedirects(c, "http://google.com", 1) | ||
| return DoRedirects(c, "http://"+addr, 1) | ||
| }) | ||
| resp, err1 := app.Test(httptest.NewRequest(fiber.MethodGet, "/test", nil)) | ||
| resp, err1 := app.Test(httptest.NewRequest(fiber.MethodGet, "/test", nil), 2000) | ||
| utils.AssertEqual(t, nil, err1) | ||
| _, err := io.ReadAll(resp.Body) | ||
| body, err := io.ReadAll(resp.Body) | ||
| utils.AssertEqual(t, nil, err) | ||
| utils.AssertEqual(t, "final", string(body)) | ||
| utils.AssertEqual(t, fiber.StatusOK, resp.StatusCode) | ||
@@ -445,8 +492,11 @@ utils.AssertEqual(t, "/test", resp.Request.URL.String()) | ||
| t.Parallel() | ||
| _, addr := createRedirectServer(t) | ||
| app := fiber.New() | ||
| app.Get("/test", func(c *fiber.Ctx) error { | ||
| return DoRedirects(c, "http://google.com", 0) | ||
| return DoRedirects(c, "http://"+addr, 0) | ||
| }) | ||
| resp, err1 := app.Test(httptest.NewRequest(fiber.MethodGet, "/test", nil)) | ||
| resp, err1 := app.Test(httptest.NewRequest(fiber.MethodGet, "/test", nil), 2000) | ||
| utils.AssertEqual(t, nil, err1) | ||
@@ -464,3 +514,3 @@ body, err := io.ReadAll(resp.Body) | ||
| _, addr := createProxyTestServer(t, func(c *fiber.Ctx) error { | ||
| _, addr := createProxyTestServerIPv4(t, func(c *fiber.Ctx) error { | ||
| return c.SendString("proxied") | ||
@@ -487,3 +537,3 @@ }) | ||
| _, addr := createProxyTestServer(t, func(c *fiber.Ctx) error { | ||
| _, addr := createProxyTestServerIPv4(t, func(c *fiber.Ctx) error { | ||
| time.Sleep(time.Second * 5) | ||
@@ -506,3 +556,3 @@ return c.SendString("proxied") | ||
| _, addr := createProxyTestServer(t, func(c *fiber.Ctx) error { | ||
| _, addr := createProxyTestServerIPv4(t, func(c *fiber.Ctx) error { | ||
| return c.SendString("proxied") | ||
@@ -529,3 +579,3 @@ }) | ||
| _, addr := createProxyTestServer(t, func(c *fiber.Ctx) error { | ||
| _, addr := createProxyTestServerIPv4(t, func(c *fiber.Ctx) error { | ||
| time.Sleep(time.Second * 5) | ||
@@ -548,3 +598,3 @@ return c.SendString("proxied") | ||
| _, addr := createProxyTestServer(t, func(c *fiber.Ctx) error { | ||
| _, addr := createProxyTestServerIPv4(t, func(c *fiber.Ctx) error { | ||
| return c.SendString("hello world") | ||
@@ -626,3 +676,3 @@ }) | ||
| target, addr := createProxyTestServer(t, func(c *fiber.Ctx) error { | ||
| target, addr := createProxyTestServerIPv4(t, func(c *fiber.Ctx) error { | ||
| return c.SendStatus(fiber.StatusTeapot) | ||
@@ -696,3 +746,3 @@ }) | ||
| _, addr := createProxyTestServer(t, func(c *fiber.Ctx) error { | ||
| _, addr := createProxyTestServerIPv4(t, func(c *fiber.Ctx) error { | ||
| return c.SendString("forwarded") | ||
@@ -699,0 +749,0 @@ }) |
Sorry, the diff of this file is too big to display