Skip to content

🐛 Connection was forcibly closed by a peer instead of 413(Request Entity Too Large) when uploading Large Files #1940

@rngallen

Description

@rngallen

Fiber version v2.34.1

**I have modified BodyLimit to 5Mb
When I upload a file having more than specified bodyLimit instead of getting status 413, I receive connection is closed **

Code snippet
image

package main

import (
"github.com/gofiber/fiber/v2"
"github.com/goccy/go-json"
)

func main() {
  app := fiber.New(fiber.Config{
		// Prefork:       true,
		CaseSensitive: true,
		StrictRouting: true,
		ServerHeader:  "Fiber",
		AppName:       "Fiber v1.0.1",
		JSONEncoder:   json.Marshal,
		JSONDecoder:   json.Unmarshal,
		BodyLimit:     5 * 1024 * 1024, // 5 Mb
})
app.Static("/media", "./media")

  // Steps to reproduce
app.Post("/", func(c *fiber.Ctx) error {
		if file, err := c.FormFile("document"); err == nil {
			if err := c.SaveFile(file, fmt.Sprintf("./media/%s", file.Filename)); err == nil {
				return c.Status(200).JSON(fiber.Map{"msg":"file uploaded"})
			}
			return c.Status(200).JSON(fiber.Map{"msg": err.Error()})
		}
		return c.Status(200).JSON(fiber.Map{"msg": err.Error()})
	})

  log.Fatal(app.Listen(":3000"))
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions