Skip to content

Commit

Permalink
Add ReadBufferSize & WriteBufferSize
Browse files Browse the repository at this point in the history
  • Loading branch information
Fenny committed Jun 15, 2020
1 parent e8d5c78 commit e745960
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
29 changes: 25 additions & 4 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
)

// Version of current package
const Version = "1.11.1"
const Version = "1.12.0"

// Map is a shortcut for map[string]interface{}, useful for JSON returns
type Map map[string]interface{}
Expand Down Expand Up @@ -143,6 +143,17 @@ type Settings struct {
// Default: unlimited
IdleTimeout time.Duration

// Per-connection buffer size for requests' reading.
// This also limits the maximum header size.
// Increase this buffer if your clients send multi-KB RequestURIs
// and/or multi-KB headers (for example, BIG cookies).
// Default 4096
ReadBufferSize int

// Per-connection buffer size for responses' writing.
// Default 4096
WriteBufferSize int

// CompressedFileSuffix adds suffix to the original file name and
// tries saving the resulting compressed file under the new file name.
// Default: ".fiber.gz"
Expand Down Expand Up @@ -177,9 +188,11 @@ type Static struct {

// default settings
var (
defaultBodyLimit = 4 * 1024 * 1024
defaultConcurrency = 256 * 1024
defaultErrorHandler = func(ctx *Ctx, err error) {
defaultBodyLimit = 4 * 1024 * 1024
defaultConcurrency = 256 * 1024
defaultReadBufferSize = 4096
defaultWriteBufferSize = 4096
defaultErrorHandler = func(ctx *Ctx, err error) {
code := StatusInternalServerError
if e, ok := err.(*Error); ok {
code = e.Code
Expand Down Expand Up @@ -218,6 +231,12 @@ func New(settings ...*Settings) *App {
if app.Settings.Concurrency <= 0 {
app.Settings.Concurrency = defaultConcurrency
}
if app.Settings.ReadBufferSize <= 0 {
app.Settings.ReadBufferSize = defaultReadBufferSize
}
if app.Settings.WriteBufferSize <= 0 {
app.Settings.WriteBufferSize = defaultWriteBufferSize
}
// Set default compressed file suffix
if app.Settings.CompressedFileSuffix == "" {
app.Settings.CompressedFileSuffix = defaultCompressedFileSuffix
Expand Down Expand Up @@ -602,6 +621,8 @@ func (app *App) init() *App {
app.server.ReadTimeout = app.Settings.ReadTimeout
app.server.WriteTimeout = app.Settings.WriteTimeout
app.server.IdleTimeout = app.Settings.IdleTimeout
app.server.ReadBufferSize = app.Settings.ReadBufferSize
app.server.WriteBufferSize = app.Settings.WriteBufferSize
app.mutex.Unlock()
return app
}
Expand Down
6 changes: 2 additions & 4 deletions path.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// ⚡️ Fiber is an Express inspired web framework written in Go with ☕️
// 🤖 Github Repository: https://github.com/gofiber/fiber
// 📌 API Documentation: https://docs.gofiber.io
// ⚠️ This path parser was inspired by ucarion/urlpath (MIT License).
// 💖 Maintained and modified for Fiber by @renewerner87

package fiber

Expand All @@ -11,10 +13,6 @@ import (
utils "github.com/gofiber/utils"
)

// ⚠️ This path parser was based on urlpath by @ucarion (MIT License).
// 💖 Modified for the Fiber router by @renanbastos93 & @renewerner87
// 🤖 ucarion/urlpath - renanbastos93/fastpath - renewerner87/fastpath

// routeParser holds the path segments and param names
type routeParser struct {
segs []paramSeg
Expand Down

0 comments on commit e745960

Please sign in to comment.