From 1341d81a4e697e09feae2e399ce0de3ba9f8790d Mon Sep 17 00:00:00 2001 From: Skyenought Date: Fri, 2 Feb 2024 08:23:51 +0800 Subject: [PATCH 1/2] tmp --- pkg/app/server/option.go | 6 ++++++ pkg/common/config/option.go | 3 +++ pkg/protocol/args.go | 12 ++++++++++-- pkg/protocol/http1/server.go | 4 ++++ pkg/route/engine.go | 1 + 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/pkg/app/server/option.go b/pkg/app/server/option.go index e7970348c..164bc767d 100644 --- a/pkg/app/server/option.go +++ b/pkg/app/server/option.go @@ -394,3 +394,9 @@ func WithDisableDefaultContentType(disable bool) config.Option { o.NoDefaultContentType = disable }} } + +func WithDisableRecycleArgs(disable bool) config.Option { + return config.Option{F: func(o *config.Options) { + o.DisableReuseArgs = disable + }} +} diff --git a/pkg/common/config/option.go b/pkg/common/config/option.go index 417955fc9..a81c1667b 100644 --- a/pkg/common/config/option.go +++ b/pkg/common/config/option.go @@ -119,6 +119,7 @@ type Options struct { // * content-type -> Content-Type // * cONTENT-lenGTH -> Content-Length DisableHeaderNamesNormalizing bool + DisableReuseArgs bool } func (o *Options) Apply(opts []Option) { @@ -256,6 +257,8 @@ func NewOptions(opts []Option) *Options { // Disabled header names' normalization, default false DisableHeaderNamesNormalizing: false, + // Disable recycling request arguments, default false + DisableReuseArgs: false, } options.Apply(opts) return options diff --git a/pkg/protocol/args.go b/pkg/protocol/args.go index fa2a670e5..c747f81f5 100644 --- a/pkg/protocol/args.go +++ b/pkg/protocol/args.go @@ -63,8 +63,13 @@ type argsScanner struct { type Args struct { noCopy nocopy.NoCopy //lint:ignore U1000 until noCopy is used - args []argsKV - buf []byte + args []argsKV + buf []byte + reuse bool +} + +func (a *Args) SetReuseArgs(b bool) { + a.reuse = b } // Set sets 'key=value' argument. @@ -74,6 +79,9 @@ func (a *Args) Set(key, value string) { // Reset clears query args. func (a *Args) Reset() { + if a.reuse { + a.args = []argsKV{} + } a.args = a.args[:0] } diff --git a/pkg/protocol/http1/server.go b/pkg/protocol/http1/server.go index a5d33f13d..add27ad64 100644 --- a/pkg/protocol/http1/server.go +++ b/pkg/protocol/http1/server.go @@ -62,6 +62,7 @@ type Option struct { DisableKeepalive bool NoDefaultServerHeader bool DisableHeaderNamesNormalizing bool + DisableReuseArgs bool MaxRequestBodySize int IdleTimeout time.Duration ReadTimeout time.Duration @@ -191,6 +192,9 @@ func (s Server) Serve(c context.Context, conn network.Conn) (err error) { ctx.Response.Header.DisableNormalizing() } + ctx.Request.PostArgs().SetReuseArgs(s.DisableReuseArgs) + ctx.Request.URI().QueryArgs().SetReuseArgs(s.DisableReuseArgs) + // Read Headers if err = req.ReadHeader(&ctx.Request.Header, zr); err == nil { if s.EnableTrace { diff --git a/pkg/route/engine.go b/pkg/route/engine.go index 8b65e6e7a..abc462336 100644 --- a/pkg/route/engine.go +++ b/pkg/route/engine.go @@ -1067,6 +1067,7 @@ func newHttp1OptionFromEngine(engine *Engine) *http1.Option { DisableHeaderNamesNormalizing: engine.options.DisableHeaderNamesNormalizing, NoDefaultDate: engine.options.NoDefaultDate, NoDefaultContentType: engine.options.NoDefaultContentType, + DisableReuseArgs: engine.options.DisableReuseArgs, } // Idle timeout of standard network must not be zero. Set it to -1 seconds if it is zero. // Due to the different triggering ways of the network library, see the actual use of this value for the detailed reasons. From 7a6a7e7ee12768cea7a86eca80bc8c40cc469e98 Mon Sep 17 00:00:00 2001 From: Skyenought Date: Fri, 2 Feb 2024 11:29:40 +0800 Subject: [PATCH 2/2] tmp --- pkg/protocol/args.go | 12 ++++++------ pkg/protocol/http1/server.go | 6 +++--- pkg/protocol/request.go | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pkg/protocol/args.go b/pkg/protocol/args.go index c747f81f5..6d09c888f 100644 --- a/pkg/protocol/args.go +++ b/pkg/protocol/args.go @@ -63,13 +63,13 @@ type argsScanner struct { type Args struct { noCopy nocopy.NoCopy //lint:ignore U1000 until noCopy is used - args []argsKV - buf []byte - reuse bool + args []argsKV + buf []byte + disableReuse bool } -func (a *Args) SetReuseArgs(b bool) { - a.reuse = b +func (a *Args) SetDisableReuseArgs(b bool) { + a.disableReuse = b } // Set sets 'key=value' argument. @@ -79,7 +79,7 @@ func (a *Args) Set(key, value string) { // Reset clears query args. func (a *Args) Reset() { - if a.reuse { + if a.disableReuse { a.args = []argsKV{} } a.args = a.args[:0] diff --git a/pkg/protocol/http1/server.go b/pkg/protocol/http1/server.go index add27ad64..ea9490605 100644 --- a/pkg/protocol/http1/server.go +++ b/pkg/protocol/http1/server.go @@ -141,6 +141,9 @@ func (s Server) Serve(c context.Context, conn network.Conn) (err error) { ctx.HTMLRender = s.HTMLRender ctx.SetConn(conn) ctx.Request.SetIsTLS(s.TLS != nil) + ctx.Request.PostArgs().SetDisableReuseArgs(s.DisableReuseArgs) + ctx.Request.URI().QueryArgs().SetDisableReuseArgs(s.DisableReuseArgs) + ctx.SetEnableTrace(s.EnableTrace) if !s.NoDefaultServerHeader { @@ -192,9 +195,6 @@ func (s Server) Serve(c context.Context, conn network.Conn) (err error) { ctx.Response.Header.DisableNormalizing() } - ctx.Request.PostArgs().SetReuseArgs(s.DisableReuseArgs) - ctx.Request.URI().QueryArgs().SetReuseArgs(s.DisableReuseArgs) - // Read Headers if err = req.ReadHeader(&ctx.Request.Header, zr); err == nil { if s.EnableTrace { diff --git a/pkg/protocol/request.go b/pkg/protocol/request.go index d04731867..88e160305 100644 --- a/pkg/protocol/request.go +++ b/pkg/protocol/request.go @@ -181,7 +181,7 @@ func (req *Request) Scheme() []byte { return req.uri.Scheme() } -// For keepalive connection reuse. +// For keepalive connection disableReuse. // It is roughly the same as ResetSkipHeader, except that the connection related fields are removed: // - req.isTLS func (req *Request) resetSkipHeaderAndConn() {