@@ -11,6 +11,7 @@ import (
11
11
"pbench/log"
12
12
"reflect"
13
13
"strings"
14
+ "sync"
14
15
"time"
15
16
)
16
17
@@ -42,6 +43,7 @@ type Client struct {
42
43
baseHeader http.Header
43
44
isTrino bool
44
45
forceHttps bool
46
+ headerMutex sync.RWMutex
45
47
}
46
48
47
49
func NewClient (serverUrl string , isTrino bool ) (* Client , error ) {
@@ -105,20 +107,26 @@ func (c *Client) GetHost() string {
105
107
}
106
108
107
109
func (c * Client ) setHeader (key , value string ) {
110
+ c .headerMutex .Lock ()
111
+ defer c .headerMutex .Unlock ()
108
112
if c .isTrino {
109
113
key = strings .Replace (key , "X-Presto" , "X-Trino" , 1 )
110
114
}
111
115
c .baseHeader .Set (key , value )
112
116
}
113
117
114
118
func (c * Client ) delHeader (key string ) {
119
+ c .headerMutex .Lock ()
120
+ defer c .headerMutex .Unlock ()
115
121
if c .isTrino {
116
122
key = strings .Replace (key , "X-Presto" , "X-Trino" , 1 )
117
123
}
118
124
c .baseHeader .Del (key )
119
125
}
120
126
121
127
func (c * Client ) getHeader (key string ) string {
128
+ c .headerMutex .RLock ()
129
+ defer c .headerMutex .RUnlock ()
122
130
if c .isTrino {
123
131
key = strings .Replace (key , "X-Presto" , "X-Trino" , 1 )
124
132
}
@@ -280,7 +288,10 @@ func (c *Client) NewRequest(method, urlStr string, body interface{}, opts ...Req
280
288
return nil , err
281
289
}
282
290
291
+ c .headerMutex .RLock ()
283
292
req .Header = c .baseHeader .Clone ()
293
+ c .headerMutex .RUnlock ()
294
+
284
295
if password , ok := c .userInfo .Password (); ok {
285
296
req .SetBasicAuth (c .userInfo .Username (), password )
286
297
}
0 commit comments