Skip to content

Commit

Permalink
Merge pull request #218 from danielgtaylor/configure-multipart-max-mem
Browse files Browse the repository at this point in the history
feat: make multipart form max memory configurable
  • Loading branch information
danielgtaylor authored Jan 24, 2024
2 parents f524213 + dcd3d6f commit c212880
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 7 deletions.
6 changes: 5 additions & 1 deletion adapters/humabunrouter/humabunrouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import (
"github.com/uptrace/bunrouter"
)

// MultipartMaxMemory is the maximum memory to use when parsing multipart
// form data.
var MultipartMaxMemory int64 = 8 * 1024

type bunContext struct {
op *huma.Operation
r bunrouter.Request
Expand Down Expand Up @@ -66,7 +70,7 @@ func (c *bunContext) BodyReader() io.Reader {
}

func (c *bunContext) GetMultipartForm() (*multipart.Form, error) {
err := c.r.ParseMultipartForm(8 * 1024)
err := c.r.ParseMultipartForm(MultipartMaxMemory)
return c.r.MultipartForm, err
}

Expand Down
6 changes: 5 additions & 1 deletion adapters/humachi/humachi.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import (
"github.com/go-chi/chi/v5"
)

// MultipartMaxMemory is the maximum memory to use when parsing multipart
// form data.
var MultipartMaxMemory int64 = 8 * 1024

type chiContext struct {
op *huma.Operation
r *http.Request
Expand Down Expand Up @@ -70,7 +74,7 @@ func (c *chiContext) BodyReader() io.Reader {
}

func (c *chiContext) GetMultipartForm() (*multipart.Form, error) {
err := c.r.ParseMultipartForm(8 * 1024)
err := c.r.ParseMultipartForm(MultipartMaxMemory)
return c.r.MultipartForm, err
}

Expand Down
6 changes: 5 additions & 1 deletion adapters/humaecho/humaecho.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import (
"github.com/labstack/echo/v4"
)

// MultipartMaxMemory is the maximum memory to use when parsing multipart
// form data.
var MultipartMaxMemory int64 = 8 * 1024

type echoCtx struct {
op *huma.Operation
orig echo.Context
Expand Down Expand Up @@ -63,7 +67,7 @@ func (c *echoCtx) BodyReader() io.Reader {
}

func (c *echoCtx) GetMultipartForm() (*multipart.Form, error) {
err := c.orig.Request().ParseMultipartForm(8 * 1024)
err := c.orig.Request().ParseMultipartForm(MultipartMaxMemory)
return c.orig.Request().MultipartForm, err
}

Expand Down
6 changes: 5 additions & 1 deletion adapters/humagin/humagin.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import (
"github.com/gin-gonic/gin"
)

// MultipartMaxMemory is the maximum memory to use when parsing multipart
// form data.
var MultipartMaxMemory int64 = 8 * 1024

type ginCtx struct {
op *huma.Operation
orig *gin.Context
Expand Down Expand Up @@ -63,7 +67,7 @@ func (c *ginCtx) BodyReader() io.Reader {
}

func (c *ginCtx) GetMultipartForm() (*multipart.Form, error) {
err := c.orig.Request.ParseMultipartForm(8 * 1024)
err := c.orig.Request.ParseMultipartForm(MultipartMaxMemory)
return c.orig.Request.MultipartForm, err
}

Expand Down
6 changes: 5 additions & 1 deletion adapters/humago/humago.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import (
"github.com/danielgtaylor/huma/v2/queryparam"
)

// MultipartMaxMemory is the maximum memory to use when parsing multipart
// form data.
var MultipartMaxMemory int64 = 8 * 1024

type goContext struct {
op *huma.Operation
r *http.Request
Expand Down Expand Up @@ -71,7 +75,7 @@ func (c *goContext) BodyReader() io.Reader {
}

func (c *goContext) GetMultipartForm() (*multipart.Form, error) {
err := c.r.ParseMultipartForm(8 * 1024)
err := c.r.ParseMultipartForm(MultipartMaxMemory)
return c.r.MultipartForm, err
}

Expand Down
6 changes: 5 additions & 1 deletion adapters/humahttprouter/humahttprouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import (
"github.com/julienschmidt/httprouter"
)

// MultipartMaxMemory is the maximum memory to use when parsing multipart
// form data.
var MultipartMaxMemory int64 = 8 * 1024

type httprouterContext struct {
op *huma.Operation
r *http.Request
Expand Down Expand Up @@ -66,7 +70,7 @@ func (c *httprouterContext) BodyReader() io.Reader {
}

func (c *httprouterContext) GetMultipartForm() (*multipart.Form, error) {
err := c.r.ParseMultipartForm(8 * 1024)
err := c.r.ParseMultipartForm(MultipartMaxMemory)
return c.r.MultipartForm, err
}

Expand Down
6 changes: 5 additions & 1 deletion adapters/humamux/humamux.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import (
"github.com/gorilla/mux"
)

// MultipartMaxMemory is the maximum memory to use when parsing multipart
// form data.
var MultipartMaxMemory int64 = 8 * 1024

type gmuxContext struct {
op *huma.Operation
r *http.Request
Expand Down Expand Up @@ -64,7 +68,7 @@ func (c *gmuxContext) BodyReader() io.Reader {
}

func (c *gmuxContext) GetMultipartForm() (*multipart.Form, error) {
err := c.r.ParseMultipartForm(8 * 1024)
err := c.r.ParseMultipartForm(MultipartMaxMemory)
return c.r.MultipartForm, err
}

Expand Down

0 comments on commit c212880

Please sign in to comment.