From e61d1f8c3cdb4498e9e678cec23080f408324372 Mon Sep 17 00:00:00 2001 From: Makis Maropoulos Date: Tue, 12 Jul 2016 15:40:06 +0200 Subject: [PATCH] Extend Read & Write BufferSize header and max request body size is 8mb now --- config/server.go | 45 ++++++++++++++++++++++++++++++++++++++------- http.go | 6 +++--- iris.go | 2 ++ 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/config/server.go b/config/server.go index 229e8c61..3ba754ff 100644 --- a/config/server.go +++ b/config/server.go @@ -9,14 +9,28 @@ import ( "github.com/kataras/fasthttp" ) -// Default values for base Server conf -const ( +// Default values for base Server conf, can be changed for global use +var ( // DefaultServerHostname returns the default hostname which is 127.0.0.1 DefaultServerHostname = "127.0.0.1" // DefaultServerPort returns the default port which is 8080 DefaultServerPort = 8080 - // DefaultMaxRequestBodySize is 4MB - DefaultMaxRequestBodySize = fasthttp.DefaultMaxRequestBodySize + // DefaultMaxRequestBodySize is 8MB + DefaultMaxRequestBodySize = 2 * fasthttp.DefaultMaxRequestBodySize + + // 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 buffer size is 8MB + DefaultReadBufferSize = 8096 + + // Per-connection buffer size for responses' writing. + // + // Default buffer size is 8MB + DefaultWriteBufferSize = 8096 ) var ( @@ -39,8 +53,22 @@ type Server struct { // // The server rejects requests with bodies exceeding this limit. // - // By default request body size is 4MB. - MaxRequestBodySize int64 + // By default request body size is 8MB. + MaxRequestBodySize int + + // 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 buffer size is used if not set. + ReadBufferSize int + + // Per-connection buffer size for responses' writing. + // + // Default buffer size is used if not set. + WriteBufferSize int // RedirectTo, defaults to empty, set it in order to override the station's handler and redirect all requests to this address which is of form(HOST:PORT or :PORT) // // NOTE: the http status is 'StatusMovedPermanently', means one-time-redirect(the browser remembers the new addr and goes to the new address without need to request something from this server @@ -86,7 +114,10 @@ func ServerParseAddr(listeningAddr string) string { // DefaultServer returns the default configs for the server func DefaultServer() Server { return Server{ListeningAddr: DefaultServerAddr, - MaxRequestBodySize: DefaultMaxRequestBodySize} + MaxRequestBodySize: DefaultMaxRequestBodySize, + ReadBufferSize: DefaultReadBufferSize, + WriteBufferSize: DefaultWriteBufferSize, + } } // Merge merges the default with the given config and returns the result diff --git a/http.go b/http.go index 70c30595..9f8b02f8 100644 --- a/http.go +++ b/http.go @@ -399,9 +399,9 @@ func (s *Server) Open(h fasthttp.RequestHandler) error { s.prepare() // do it again for any case - if s.Config.MaxRequestBodySize > config.DefaultMaxRequestBodySize { - s.Server.MaxRequestBodySize = int(s.Config.MaxRequestBodySize) - } + s.Server.MaxRequestBodySize = s.Config.MaxRequestBodySize + s.Server.ReadBufferSize = s.Config.ReadBufferSize + s.Server.WriteBufferSize = s.Config.WriteBufferSize if s.Config.RedirectTo != "" { // override the handler and redirect all requests to this addr diff --git a/iris.go b/iris.go index 53d94149..196cda73 100644 --- a/iris.go +++ b/iris.go @@ -372,6 +372,8 @@ func ListenTo(cfg config.Server) error { // it's a blocking func func (s *Framework) ListenTo(cfg config.Server) (err error) { s.Servers.Add(cfg) + c := config.DefaultServer().MergeSingle(cfg) + s.Servers.Add(c) return s.Go() }