fix conflicts

This commit is contained in:
Evgeniy Kulikov 2021-02-12 15:24:52 +03:00
parent cbaf9e6142
commit a428a0b1b3
No known key found for this signature in database
GPG key ID: BF6AEE0A2A699BF2
4 changed files with 52 additions and 7 deletions

View file

@ -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_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:
HTTP_GW_PEERS_[N]_ADDRESS = string

11
app.go
View file

@ -97,6 +97,17 @@ func newApp(ctx context.Context, opt ...Option) App {
a.web.DisableHeaderNamesNormalizing = true
a.web.NoDefaultServerHeader = 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)

View file

@ -4,6 +4,7 @@ import (
"fmt"
"io"
"os"
"reflect"
"sort"
"strconv"
"strings"
@ -11,6 +12,8 @@ import (
"github.com/spf13/pflag"
"github.com/spf13/viper"
"github.com/valyala/fasthttp"
"go.uber.org/zap"
)
type empty int
@ -33,11 +36,12 @@ const (
cfgKeepalivePermitWithoutStream = "keepalive.permit_without_stream"
// Web
cfgWebReadBufferSize = "web.read_buffer_size"
cfgWebWriteBufferSize = "web.write_buffer_size"
cfgWebReadTimeout = "web.read_timeout"
cfgWebWriteTimeout = "web.write_timeout"
cfgWebConnectionPerHost = "web.connection_per_host"
cfgWebReadBufferSize = "web.read_buffer_size"
cfgWebWriteBufferSize = "web.write_buffer_size"
cfgWebReadTimeout = "web.read_timeout"
cfgWebWriteTimeout = "web.write_timeout"
cfgWebStreamRequestBody = "web.stream_request_body"
cfgWebMaxRequestBodySize = "web.max_request_body_size"
// Timeouts
cfgConTimeout = "connect_timeout"
@ -86,6 +90,26 @@ var ignore = map[string]struct{}{
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 {
v := viper.New()
v.AutomaticEnv()
@ -140,7 +164,8 @@ func settings() *viper.Viper {
v.SetDefault(cfgWebWriteBufferSize, 4096)
v.SetDefault(cfgWebReadTimeout, time.Second*15)
v.SetDefault(cfgWebWriteTimeout, time.Minute)
v.SetDefault(cfgWebConnectionPerHost, 10)
v.SetDefault(cfgWebStreamRequestBody, true)
v.SetDefault(cfgWebMaxRequestBodySize, fasthttp.DefaultMaxRequestBodySize)
// upload header
v.SetDefault(cfgUploaderHeaderEnableDefaultTimestamp, false)

View file

@ -55,7 +55,7 @@ func (a *app) upload(c *fasthttp.RequestCtx) {
defer func() {
// 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()))
}