Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
Skyenought committed Feb 2, 2024
1 parent 0619701 commit 1341d81
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
6 changes: 6 additions & 0 deletions pkg/app/server/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}}
}
3 changes: 3 additions & 0 deletions pkg/common/config/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions pkg/protocol/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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]
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/protocol/http1/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type Option struct {
DisableKeepalive bool
NoDefaultServerHeader bool
DisableHeaderNamesNormalizing bool
DisableReuseArgs bool
MaxRequestBodySize int
IdleTimeout time.Duration
ReadTimeout time.Duration
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions pkg/route/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 1341d81

Please sign in to comment.