Allow setting arbitrary headers in API client
This commit is contained in:
parent
13706b9be4
commit
9064930f08
|
@ -314,6 +314,8 @@ type Config struct {
|
|||
Namespace string
|
||||
|
||||
TLSConfig TLSConfig
|
||||
|
||||
Headers map[string]string
|
||||
}
|
||||
|
||||
// TLSConfig is used to generate a TLSClientConfig that's useful for talking to
|
||||
|
@ -855,6 +857,10 @@ func (c *Client) newRequest(method, path string) *request {
|
|||
params: make(map[string][]string),
|
||||
header: make(http.Header),
|
||||
}
|
||||
|
||||
for k, v := range c.config.Headers {
|
||||
r.header.Set(k, v)
|
||||
}
|
||||
if c.config.Datacenter != "" {
|
||||
r.params.Set("dc", c.config.Datacenter)
|
||||
}
|
||||
|
|
|
@ -808,6 +808,22 @@ func TestAPI_SetWriteOptions(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestAPI_Headers(t *testing.T) {
|
||||
t.Parallel()
|
||||
c, s := makeClientWithConfig(t, func(c *Config) {
|
||||
c.Headers = map[string]string{
|
||||
"Hello": "World",
|
||||
}
|
||||
}, nil)
|
||||
defer s.Stop()
|
||||
|
||||
r := c.newRequest("GET", "/v1/kv/foo")
|
||||
|
||||
if r.header.Get("Hello") != "World" {
|
||||
t.Fatalf("bad: %v", r.header)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAPI_RequestToHTTP(t *testing.T) {
|
||||
t.Parallel()
|
||||
c, s := makeClient(t)
|
||||
|
|
Loading…
Reference in New Issue