fix(request): deep copy shared header object in request options

pull/1519/head
HFO4 2 years ago
parent c7dc143d30
commit 8494bd6eb9

@ -14,7 +14,7 @@ import (
func NewFS(zipContent string) fs.FS { func NewFS(zipContent string) fs.FS {
zipReader, err := zip.NewReader(strings.NewReader(zipContent), int64(len(zipContent))) zipReader, err := zip.NewReader(strings.NewReader(zipContent), int64(len(zipContent)))
if err != nil { 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 var files []file

@ -44,6 +44,12 @@ func newDefaultOption() *options {
} }
} }
func (o *options) clone() options {
newOptions := *o
newOptions.header = o.header.Clone()
return newOptions
}
// WithTimeout 设置请求超时 // WithTimeout 设置请求超时
func WithTimeout(t time.Duration) Option { func WithTimeout(t time.Duration) Option {
return optionFunc(func(o *options) { return optionFunc(func(o *options) {

@ -56,7 +56,7 @@ func NewClient(opts ...Option) Client {
func (c *HTTPClient) Request(method, target string, body io.Reader, opts ...Option) *Response { func (c *HTTPClient) Request(method, target string, body io.Reader, opts ...Option) *Response {
// 应用额外设置 // 应用额外设置
c.mu.Lock() c.mu.Lock()
options := *c.options options := c.options.clone()
c.mu.Unlock() c.mu.Unlock()
for _, o := range opts { for _, o := range opts {
o.apply(&options) o.apply(&options)

Loading…
Cancel
Save