fix conflicts
This commit is contained in:
parent
cbaf9e6142
commit
a428a0b1b3
4 changed files with 52 additions and 7 deletions
|
@ -73,6 +73,15 @@ If false, when there are no active RPCs, Time and Timeout will be ignored and no
|
||||||
|
|
||||||
HTTP_GW_UPLOAD_HEADER_USE_DEFAULT_TIMESTAMP=bool - enable/disable adding current timestamp attribute when object uploads
|
HTTP_GW_UPLOAD_HEADER_USE_DEFAULT_TIMESTAMP=bool - enable/disable adding current timestamp attribute when object uploads
|
||||||
|
|
||||||
|
HTTP_GW_WEB_READ_BUFFER_SIZE=4096 - per-connection buffer size for requests' reading
|
||||||
|
HTTP_GW_WEB_READ_TIMEOUT=15s - an amount of time allowed to read the full request including body
|
||||||
|
HTTP_GW_WEB_WRITE_BUFFER_SIZE=4096 - per-connection buffer size for responses' writing
|
||||||
|
HTTP_GW_WEB_WRITE_TIMEOUT=1m0s - maximum duration before timing out writes of the response
|
||||||
|
HTTP_GW_WEB_STREAM_REQUEST_BODY=true - enables request body streaming, and calls the handler sooner when given
|
||||||
|
body is larger then the current limit
|
||||||
|
HTTP_GW_WEB_MAX_REQUEST_BODY_SIZE=4194304 - maximum request body size, server rejects requests with bodies exceeding
|
||||||
|
this limit
|
||||||
|
|
||||||
Peers preset:
|
Peers preset:
|
||||||
|
|
||||||
HTTP_GW_PEERS_[N]_ADDRESS = string
|
HTTP_GW_PEERS_[N]_ADDRESS = string
|
||||||
|
|
11
app.go
11
app.go
|
@ -97,6 +97,17 @@ func newApp(ctx context.Context, opt ...Option) App {
|
||||||
a.web.DisableHeaderNamesNormalizing = true
|
a.web.DisableHeaderNamesNormalizing = true
|
||||||
a.web.NoDefaultServerHeader = true
|
a.web.NoDefaultServerHeader = true
|
||||||
a.web.NoDefaultContentType = true
|
a.web.NoDefaultContentType = true
|
||||||
|
a.web.MaxRequestBodySize = a.cfg.GetInt(cfgWebMaxRequestBodySize)
|
||||||
|
|
||||||
|
// FIXME don't work with StreamRequestBody,
|
||||||
|
// some bugs with readMultipartForm
|
||||||
|
// a.web.DisablePreParseMultipartForm = true
|
||||||
|
|
||||||
|
// body streaming
|
||||||
|
// TODO should be replaced in future with
|
||||||
|
//
|
||||||
|
// a.web.StreamRequestBody = v.GetBool(cfgWebStreamRequestBody)
|
||||||
|
checkAndEnableStreaming(a.log, a.cfg, a.web)
|
||||||
// -- -- -- -- -- -- -- -- -- --
|
// -- -- -- -- -- -- -- -- -- --
|
||||||
|
|
||||||
connections := make(map[string]float64)
|
connections := make(map[string]float64)
|
||||||
|
|
37
settings.go
37
settings.go
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -11,6 +12,8 @@ import (
|
||||||
|
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
"github.com/valyala/fasthttp"
|
||||||
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
type empty int
|
type empty int
|
||||||
|
@ -33,11 +36,12 @@ const (
|
||||||
cfgKeepalivePermitWithoutStream = "keepalive.permit_without_stream"
|
cfgKeepalivePermitWithoutStream = "keepalive.permit_without_stream"
|
||||||
|
|
||||||
// Web
|
// Web
|
||||||
cfgWebReadBufferSize = "web.read_buffer_size"
|
cfgWebReadBufferSize = "web.read_buffer_size"
|
||||||
cfgWebWriteBufferSize = "web.write_buffer_size"
|
cfgWebWriteBufferSize = "web.write_buffer_size"
|
||||||
cfgWebReadTimeout = "web.read_timeout"
|
cfgWebReadTimeout = "web.read_timeout"
|
||||||
cfgWebWriteTimeout = "web.write_timeout"
|
cfgWebWriteTimeout = "web.write_timeout"
|
||||||
cfgWebConnectionPerHost = "web.connection_per_host"
|
cfgWebStreamRequestBody = "web.stream_request_body"
|
||||||
|
cfgWebMaxRequestBodySize = "web.max_request_body_size"
|
||||||
|
|
||||||
// Timeouts
|
// Timeouts
|
||||||
cfgConTimeout = "connect_timeout"
|
cfgConTimeout = "connect_timeout"
|
||||||
|
@ -86,6 +90,26 @@ var ignore = map[string]struct{}{
|
||||||
|
|
||||||
func (empty) Read([]byte) (int, error) { return 0, io.EOF }
|
func (empty) Read([]byte) (int, error) { return 0, io.EOF }
|
||||||
|
|
||||||
|
// checkAndEnableStreaming is temporary shim, should be used before
|
||||||
|
// `StreamRequestBody` is not merged in fasthttp master
|
||||||
|
// TODO should be removed in future
|
||||||
|
func checkAndEnableStreaming(l *zap.Logger, v *viper.Viper, i interface{}) {
|
||||||
|
vi := reflect.ValueOf(i)
|
||||||
|
|
||||||
|
if vi.Type().Kind() != reflect.Ptr {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
field := vi.Elem().FieldByName("StreamRequestBody")
|
||||||
|
if !field.IsValid() || field.Kind() != reflect.Bool {
|
||||||
|
l.Warn("stream request body not supported")
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
field.SetBool(v.GetBool(cfgWebStreamRequestBody))
|
||||||
|
}
|
||||||
|
|
||||||
func settings() *viper.Viper {
|
func settings() *viper.Viper {
|
||||||
v := viper.New()
|
v := viper.New()
|
||||||
v.AutomaticEnv()
|
v.AutomaticEnv()
|
||||||
|
@ -140,7 +164,8 @@ func settings() *viper.Viper {
|
||||||
v.SetDefault(cfgWebWriteBufferSize, 4096)
|
v.SetDefault(cfgWebWriteBufferSize, 4096)
|
||||||
v.SetDefault(cfgWebReadTimeout, time.Second*15)
|
v.SetDefault(cfgWebReadTimeout, time.Second*15)
|
||||||
v.SetDefault(cfgWebWriteTimeout, time.Minute)
|
v.SetDefault(cfgWebWriteTimeout, time.Minute)
|
||||||
v.SetDefault(cfgWebConnectionPerHost, 10)
|
v.SetDefault(cfgWebStreamRequestBody, true)
|
||||||
|
v.SetDefault(cfgWebMaxRequestBodySize, fasthttp.DefaultMaxRequestBodySize)
|
||||||
|
|
||||||
// upload header
|
// upload header
|
||||||
v.SetDefault(cfgUploaderHeaderEnableDefaultTimestamp, false)
|
v.SetDefault(cfgUploaderHeaderEnableDefaultTimestamp, false)
|
||||||
|
|
|
@ -55,7 +55,7 @@ func (a *app) upload(c *fasthttp.RequestCtx) {
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
// if temporary reader can be closed - close it
|
// if temporary reader can be closed - close it
|
||||||
if closer := tmp.(io.Closer); closer != nil {
|
if closer, ok := tmp.(io.Closer); ok && closer != nil {
|
||||||
log.Debug("close temporary multipart/form file", zap.Error(closer.Close()))
|
log.Debug("close temporary multipart/form file", zap.Error(closer.Close()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue