Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion config/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,30 @@ type (
// default is 32 << 20 (32 mb), MaxBodySize use go runtime default zero value
// -1 : unlimted
// 0 : use default value
MaxBodySize int64 `xml:"MaxBodySize,attr"` // To limit the request's body size to be read
MaxBodySize int64 `xml:"MaxBodySize,attr"`

// To limit the request's body size to be read with Millisecond
// ReadTimeout is the maximum duration for reading the entire
// request, including the body.
ReadTimeout int64 `xml:"ReadTimeout,attr"`

// ReadHeaderTimeout is the amount of time allowed to read
// request headers with Millisecond. The connection's read deadline is reset
// after reading the headers and the Handler can decide what
// is considered too slow for the body.
ReadHeaderTimeout int64 `xml:"ReadHeaderTimeout,attr"`

// WriteTimeout is the maximum duration before timing out
// writes of the response with Millisecond. It is reset whenever a new
// request's header is read. Like ReadTimeout, it does not
// let Handlers make decisions on a per-request basis.
WriteTimeout int64 `xml:"WriteTimeout,attr"`

// IdleTimeout is the maximum amount of time to wait for the
// next request when keep-alives are enabled with Millisecond. If IdleTimeout
// is zero, the value of ReadTimeout is used. If both are
// zero, ReadHeaderTimeout is used.
IdleTimeout int64 `xml:"IdleTimeout,attr"`
}

// SessionNode dotweb app's session config
Expand Down
2 changes: 1 addition & 1 deletion consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package dotweb
// Global define
const (
// Version current version
Version = "1.7.18"
Version = "1.7.19"
)

// Log define
Expand Down
2 changes: 1 addition & 1 deletion dotweb.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ func (app *DotWeb) initAppConfig() {
app.Config.App.RunMode = RunMode_Development
}

app.HttpServer.initConfig()
app.HttpServer.initConfig(app.Config)

// detailed request metrics
if config.Server.EnabledDetailRequestData {
Expand Down
43 changes: 40 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package dotweb

import (
"compress/gzip"
"github.com/devfeel/dotweb/logger"
"io"
"net/http"
"net/url"
"strings"
"sync"

"github.com/devfeel/dotweb/logger"
"time"

"github.com/devfeel/dotweb/core"
"github.com/devfeel/dotweb/session"
Expand Down Expand Up @@ -84,7 +84,19 @@ func NewHttpServer() *HttpServer {
}

// initConfig init config from app config
func (server *HttpServer) initConfig() {
func (server *HttpServer) initConfig(config *config.Config) {
if config.Server.WriteTimeout > 0 {
server.stdServer.WriteTimeout = time.Duration(config.Server.WriteTimeout) * time.Millisecond
}
if config.Server.ReadTimeout > 0 {
server.stdServer.ReadTimeout = time.Duration(config.Server.ReadTimeout) * time.Millisecond
}
if config.Server.ReadHeaderTimeout > 0 {
server.stdServer.ReadHeaderTimeout = time.Duration(config.Server.ReadHeaderTimeout) * time.Millisecond
}
if config.Server.IdleTimeout > 0 {
server.stdServer.IdleTimeout = time.Duration(config.Server.IdleTimeout) * time.Millisecond
}
}

// ServerConfig a shortcut for App.Config.ServerConfig
Expand Down Expand Up @@ -475,6 +487,31 @@ func (server *HttpServer) SetEnabledStaticFileMiddleware(isEnabled bool) {
server.Logger().Debug("DotWeb:HttpServer SetEnabledStaticFileMiddleware ["+strconv.FormatBool(isEnabled)+"]", LogTarget_HttpServer)
}

// SetReadTimeout To limit the request's body size to be read with Millisecond
func (server *HttpServer) SetReadTimeout(readTimeout int64) {
server.ServerConfig().ReadTimeout = readTimeout
server.Logger().Debug("DotWeb:HttpServer SetReadTimeout ["+strconv.FormatInt(readTimeout, 10)+"]", LogTarget_HttpServer)
}

// SetReadHeaderTimeout ReadHeaderTimeout is the amount of time allowed to read request headers with Millisecond
func (server *HttpServer) SetReadHeaderTimeout(readHeaderTimeout int64) {
server.ServerConfig().ReadHeaderTimeout = readHeaderTimeout
server.Logger().Debug("DotWeb:HttpServer SetReadHeaderTimeout ["+strconv.FormatInt(readHeaderTimeout, 10)+"]", LogTarget_HttpServer)
}

// SetIdleTimeout IdleTimeout is the maximum amount of time to wait for the next request when keep-alives are enabled with Millisecond
func (server *HttpServer) SetIdleTimeout(idleTimeout int64) {
server.ServerConfig().IdleTimeout = idleTimeout
server.Logger().Debug("DotWeb:HttpServer SetIdleTimeout ["+strconv.FormatInt(idleTimeout, 10)+"]", LogTarget_HttpServer)
}

// SetWriteTimeout WriteTimeout is the maximum duration before timing out
// writes of the response with Millisecond
func (server *HttpServer) SetWriteTimeout(writeTimeout int64) {
server.ServerConfig().WriteTimeout = writeTimeout
server.Logger().Debug("DotWeb:HttpServer SetWriteTimeout ["+strconv.FormatInt(writeTimeout, 10)+"]", LogTarget_HttpServer)
}

// SetMaxBodySize set body size to limit read
func (server *HttpServer) SetMaxBodySize(maxBodySize int64) {
server.ServerConfig().MaxBodySize = maxBodySize
Expand Down
7 changes: 6 additions & 1 deletion version.MD
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
## dotweb版本记录:

####Version 1.7.18

####Version 1.7.19
* feature: add SetReadTimeout\SetReadHeaderTimeout\SetIdleTimeoutSetWriteTimeout func() in HttpServer
* 2021-04-20 13:00 at ShangHai

####Version 1.7.18
* Bug fix: fix deepcopy middleware not success
* 2021-04-20 13:00 at ShangHai

Expand Down