From 8494bd6eb9c8d1df25c1e1fbadd615015c7f8ca1 Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Sat, 15 Oct 2022 16:16:17 +0800 Subject: [PATCH] fix(request): deep copy shared header object in request options --- assets.zip | 0 bootstrap/fs.go | 2 +- pkg/request/options.go | 6 ++++++ pkg/request/request.go | 2 +- 4 files changed, 8 insertions(+), 2 deletions(-) delete mode 100644 assets.zip diff --git a/assets.zip b/assets.zip deleted file mode 100644 index e69de29..0000000 diff --git a/bootstrap/fs.go b/bootstrap/fs.go index d2f7c1e..a82396c 100644 --- a/bootstrap/fs.go +++ b/bootstrap/fs.go @@ -14,7 +14,7 @@ import ( func NewFS(zipContent string) fs.FS { zipReader, err := zip.NewReader(strings.NewReader(zipContent), int64(len(zipContent))) if err != nil { - util.Log().Panic("静态资源不是合法的zip文件: %s", err) + util.Log().Panic("Static resource is not a valid zip file: %s", err) } var files []file diff --git a/pkg/request/options.go b/pkg/request/options.go index dc0391e..63bc8dd 100644 --- a/pkg/request/options.go +++ b/pkg/request/options.go @@ -44,6 +44,12 @@ func newDefaultOption() *options { } } +func (o *options) clone() options { + newOptions := *o + newOptions.header = o.header.Clone() + return newOptions +} + // WithTimeout 设置请求超时 func WithTimeout(t time.Duration) Option { return optionFunc(func(o *options) { diff --git a/pkg/request/request.go b/pkg/request/request.go index 9a5d860..2947085 100644 --- a/pkg/request/request.go +++ b/pkg/request/request.go @@ -56,7 +56,7 @@ func NewClient(opts ...Option) Client { func (c *HTTPClient) Request(method, target string, body io.Reader, opts ...Option) *Response { // 应用额外设置 c.mu.Lock() - options := *c.options + options := c.options.clone() c.mu.Unlock() for _, o := range opts { o.apply(&options)