2018-04-04 13:28:35 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ReadWriteHandler interface {
|
|
|
|
GetMaxMessageSize() int64
|
|
|
|
GetReadBufferSize() int
|
|
|
|
GetWriteBufferSize() int
|
|
|
|
GetReadTimeout() time.Duration
|
|
|
|
GetWriteTimeout() time.Duration
|
|
|
|
}
|
|
|
|
|
|
|
|
type ReadWriteHandlers struct {
|
2018-04-12 05:55:01 +00:00
|
|
|
MaxMessageSize int64 `json:"maxMessageSize"`
|
2018-04-04 13:28:35 +00:00
|
|
|
// 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.
|
2018-04-12 05:55:01 +00:00
|
|
|
ReadBufferSize int `json:"readBufferSize"`
|
2018-04-04 13:28:35 +00:00
|
|
|
// Per-connection buffer size for responses' writing.
|
|
|
|
//
|
|
|
|
// Default buffer size is used if not set.
|
2018-04-12 05:55:01 +00:00
|
|
|
WriteBufferSize int `json:"writeBufferSize"`
|
2018-04-04 13:28:35 +00:00
|
|
|
// Maximum duration for reading the full request (including body).
|
|
|
|
//
|
|
|
|
// This also limits the maximum duration for idle keep-alive
|
|
|
|
// connections.
|
|
|
|
//
|
|
|
|
// By default request read timeout is unlimited.
|
2018-04-12 05:55:01 +00:00
|
|
|
ReadTimeout time.Duration `json:"readTimeout"`
|
2018-04-04 13:28:35 +00:00
|
|
|
|
|
|
|
// Maximum duration for writing the full response (including body).
|
|
|
|
//
|
|
|
|
// By default response write timeout is unlimited.
|
2018-04-12 05:55:01 +00:00
|
|
|
WriteTimeout time.Duration `json:"writeTimeout"`
|
2018-04-04 13:28:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (rwh *ReadWriteHandlers) GetMaxMessageSize() int64 {
|
|
|
|
return rwh.MaxMessageSize
|
|
|
|
}
|
|
|
|
func (rwh *ReadWriteHandlers) GetReadBufferSize() int {
|
|
|
|
return rwh.ReadBufferSize
|
|
|
|
}
|
|
|
|
func (rwh *ReadWriteHandlers) GetWriteBufferSize() int {
|
|
|
|
return rwh.WriteBufferSize
|
|
|
|
}
|
|
|
|
func (rwh *ReadWriteHandlers) GetReadTimeout() time.Duration {
|
|
|
|
return rwh.ReadTimeout
|
|
|
|
}
|
|
|
|
func (rwh *ReadWriteHandlers) GetWriteTimeout() time.Duration {
|
|
|
|
return rwh.WriteTimeout
|
|
|
|
}
|
2018-04-05 15:15:29 +00:00
|
|
|
|
2018-04-12 05:55:01 +00:00
|
|
|
func (rwh *ReadWriteHandlers) Clone() *ReadWriteHandlers {
|
|
|
|
return &ReadWriteHandlers{
|
|
|
|
MaxMessageSize: rwh.MaxMessageSize,
|
|
|
|
ReadBufferSize: rwh.ReadBufferSize,
|
|
|
|
WriteBufferSize: rwh.WriteBufferSize,
|
|
|
|
ReadTimeout: rwh.ReadTimeout,
|
|
|
|
WriteTimeout: rwh.WriteTimeout,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-04 13:28:35 +00:00
|
|
|
func (rwh *ReadWriteHandlers) Validate() error {
|
|
|
|
if rwh.MaxMessageSize <= 0 {
|
|
|
|
rwh.MaxMessageSize = DefaultMaxMessageSize
|
|
|
|
}
|
|
|
|
if rwh.ReadBufferSize <= 0 {
|
|
|
|
rwh.ReadBufferSize = DefaultReadBufferSize
|
|
|
|
}
|
|
|
|
if rwh.WriteBufferSize <= 0 {
|
|
|
|
rwh.WriteBufferSize = DefaultWriteBufferSize
|
|
|
|
}
|
|
|
|
if rwh.ReadTimeout <= 0 {
|
|
|
|
rwh.ReadTimeout = DefaultReadTimeout
|
|
|
|
}
|
|
|
|
if rwh.WriteTimeout <= 0 {
|
|
|
|
rwh.WriteTimeout = DefaultWriteTimeout
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|