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
|
Namespace string
|
||||||
|
|
||||||
TLSConfig TLSConfig
|
TLSConfig TLSConfig
|
||||||
|
|
||||||
|
Headers map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
// TLSConfig is used to generate a TLSClientConfig that's useful for talking to
|
// 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),
|
params: make(map[string][]string),
|
||||||
header: make(http.Header),
|
header: make(http.Header),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for k, v := range c.config.Headers {
|
||||||
|
r.header.Set(k, v)
|
||||||
|
}
|
||||||
if c.config.Datacenter != "" {
|
if c.config.Datacenter != "" {
|
||||||
r.params.Set("dc", 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) {
|
func TestAPI_RequestToHTTP(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
c, s := makeClient(t)
|
c, s := makeClient(t)
|
||||||
|
|
Loading…
Reference in New Issue