Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP feat: add option sets whether reset args when reset #1059

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
disableReuse bool
}

func (a *Args) SetDisableReuseArgs(b bool) {
a.disableReuse = 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.disableReuse {
a.args = []argsKV{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里不需要

}
a.args = a.args[:0]
}
Copy link
Member

@li-jin-gou li-jin-gou Feb 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

允许自定义 Reset 函数的行为即可


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 @@ -140,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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/protocol/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
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
Loading