Skip to content

Commit

Permalink
Merge pull request #188 from yoyofx/dev
Browse files Browse the repository at this point in the history
fixed request body max bytes that when upload file
  • Loading branch information
yoyofx authored Oct 10, 2021
2 parents fce3478 + a53eb09 commit b2a1398
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion examples/simpleweb/config_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ yoyogo:
type: "fasthttp"
address: ":8080"
path: "app"
max_request_size: 2096157
max_request_size: 31457280
session:
name: "YOYOGO_SESSIONID"
timeout: 3600
Expand Down
15 changes: 15 additions & 0 deletions examples/simpleweb/contollers/usercontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,18 @@ func (controller UserController) QueryBinding(ctx *context.HttpContext) mvc.ApiR
}
return controller.OK(userInfo)
}

type UploadForm struct {
mvc.RequestBody
File *multipart.FileHeader `form:"file1"`
Key string `form:"key"`
}

func (controller UserController) Upload(form *UploadForm) mvc.ApiResult {
return controller.OK(context.H{
"file": form.File.Filename,
"size": form.File.Size,
"key": form.Key,
})

}
4 changes: 2 additions & 2 deletions examples/simpleweb/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ go 1.16
require (
github.com/fasthttp/websocket v1.4.3
github.com/go-sql-driver/mysql v1.6.0
github.com/jinzhu/copier v0.3.2
github.com/jinzhu/copier v0.3.2 // indirect
github.com/yoyofx/yoyogo v0.0.0
github.com/yoyofxteam/dependencyinjection v1.0.1
github.com/yoyofxteam/reflectx v0.2.3
github.com/yoyofxteam/reflectx v0.2.3 // indirect
gorm.io/gorm v1.21.11
)

Expand Down
4 changes: 4 additions & 0 deletions web/binding/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package binding

import (
"net/http"
"strings"
"unsafe"
)

Expand Down Expand Up @@ -80,6 +81,9 @@ func Default(method, contentType string) Binding {
if method == http.MethodGet {
return Form
}
if strings.HasPrefix(contentType, MIMEMultipartPOSTForm) {
return FormMultipart
}

switch contentType {
case MIMEJSON:
Expand Down
5 changes: 3 additions & 2 deletions web/fasthttpserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ func (server *FastHttpServer) Run(context *abstractions.HostBuilderContext) (e e
fastHttpHandler := NewFastHTTPHandler(context.RequestDelegate.(IRequestDelegate))

server.webserver = &fasthttp.Server{
Handler: fastHttpHandler,
KeepHijackedConns: true,
Handler: fastHttpHandler,
KeepHijackedConns: true,
MaxRequestBodySize: int(context.HostConfiguration.Server.MaxRequestSize),
}

addr := server.Addr
Expand Down

0 comments on commit b2a1398

Please sign in to comment.