@@ -142,11 +142,11 @@ type Client struct {
142
142
proxyURL * url.URL
143
143
beforeRequest []RequestMiddleware
144
144
udBeforeRequest []RequestMiddleware
145
- udBeforeRequestLock sync.RWMutex
145
+ udBeforeRequestLock * sync.RWMutex
146
146
preReqHook PreRequestHook
147
147
successHooks []SuccessHook
148
148
afterResponse []ResponseMiddleware
149
- afterResponseLock sync.RWMutex
149
+ afterResponseLock * sync.RWMutex
150
150
requestLog RequestLogCallback
151
151
responseLog ResponseLogCallback
152
152
errorHooks []ErrorHook
@@ -1125,6 +1125,25 @@ func (c *Client) GetClient() *http.Client {
1125
1125
return c .httpClient
1126
1126
}
1127
1127
1128
+ // Clone returns a clone of the original client.
1129
+ //
1130
+ // Be carefull when using this function:
1131
+ // - Interface values are not deeply cloned. Thus, both the original and the clone will use the
1132
+ // same value.
1133
+ // - This function is not safe for concurrent use. You should only use this when you are sure that
1134
+ // the client is not being used by any other goroutine.
1135
+ //
1136
+ // Since v2.12.0
1137
+ func (c * Client ) Clone () * Client {
1138
+ // dereference the pointer and copy the value
1139
+ cc := * c
1140
+
1141
+ // lock values should not be copied - thus new values are used.
1142
+ cc .afterResponseLock = & sync.RWMutex {}
1143
+ cc .udBeforeRequestLock = & sync.RWMutex {}
1144
+ return & cc
1145
+ }
1146
+
1128
1147
//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
1129
1148
// Client Unexported methods
1130
1149
//_______________________________________________________________________
@@ -1360,9 +1379,11 @@ func createClient(hc *http.Client) *Client {
1360
1379
XMLUnmarshal : xml .Unmarshal ,
1361
1380
HeaderAuthorizationKey : http .CanonicalHeaderKey ("Authorization" ),
1362
1381
1363
- jsonEscapeHTML : true ,
1364
- httpClient : hc ,
1365
- debugBodySizeLimit : math .MaxInt32 ,
1382
+ jsonEscapeHTML : true ,
1383
+ httpClient : hc ,
1384
+ debugBodySizeLimit : math .MaxInt32 ,
1385
+ udBeforeRequestLock : & sync.RWMutex {},
1386
+ afterResponseLock : & sync.RWMutex {},
1366
1387
}
1367
1388
1368
1389
// Logger
0 commit comments