Rainbond/gateway/controller/openresty/model/http.go

94 lines
2.0 KiB
Go
Raw Normal View History

2018-11-08 17:22:26 +08:00
package model
2018-11-21 17:35:07 +08:00
import "github.com/goodrain/rainbond/cmd/gateway/option"
2018-11-23 14:34:44 +08:00
// HTTP contains data for nginx http configuration
type HTTP struct {
2018-11-08 17:22:26 +08:00
DefaultType string
SendFile bool
KeepaliveTimeout Time
2018-11-21 17:35:07 +08:00
keepaliveRequests int
2018-11-08 17:22:26 +08:00
ClientMaxBodySize Size
ClientBodyBufferSize Size
ProxyConnectTimeout Time
ProxySendTimeout Time
ProxyReadTimeout Time
ProxyBufferSize Size
ProxyBuffers Size
ProxyBusyBuffersSize Size
2018-12-05 22:06:21 +08:00
StatusPort int
2018-11-23 14:34:44 +08:00
UpstreamsDict Size
HTTPListen int
HTTPSListen int
AccessLogPath string
DisableAccessLog bool
2020-06-15 17:06:53 +08:00
AccessLogFormat string
2018-11-08 17:22:26 +08:00
}
2019-03-10 18:51:10 +08:00
// LogFormat -
2018-11-08 17:22:26 +08:00
type LogFormat struct {
Name string
Format string
}
2019-03-10 18:51:10 +08:00
// AccessLog -
2018-11-08 17:22:26 +08:00
type AccessLog struct {
Name string
Path string
}
2018-11-23 14:34:44 +08:00
// NewHTTP creates a new model.HTTP
func NewHTTP(conf *option.Config) *HTTP {
return &HTTP{
2020-06-15 18:40:20 +08:00
HTTPListen: conf.ListenPorts.HTTP,
HTTPSListen: conf.ListenPorts.HTTPS,
DefaultType: "text/html",
SendFile: true,
StatusPort: conf.ListenPorts.Status,
AccessLogPath: conf.AccessLogPath,
AccessLogFormat: func() string {
if conf.AccessLogFormat == "" {
return `$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $request_length $request_time $upstream_addr $upstream_response_length $upstream_response_time $upstream_status`
}
return conf.AccessLogFormat
}(),
DisableAccessLog: conf.AccessLogPath == "",
2018-11-08 17:22:26 +08:00
KeepaliveTimeout: Time{
Num: 30,
2018-11-08 17:22:26 +08:00
Unit: "s",
},
ClientMaxBodySize: Size{
Num: 10,
Unit: "m",
},
ClientBodyBufferSize: Size{
Num: 128,
Unit: "k",
},
ProxyConnectTimeout: Time{
Num: 75,
Unit: "s",
},
ProxySendTimeout: Time{
Num: 75,
Unit: "s",
},
ProxyReadTimeout: Time{
Num: 75,
Unit: "s",
},
ProxyBufferSize: Size{
Num: 8,
Unit: "k",
},
ProxyBuffers: Size{
Num: 32,
Unit: "k",
},
2018-11-23 14:34:44 +08:00
UpstreamsDict: Size{
Num: int(conf.ShareMemory),
Unit: "m",
2018-11-23 14:34:44 +08:00
},
2018-11-08 17:22:26 +08:00
}
}