From 921aa9cf9055575d19d967e976eabe5e6aee2872 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 24 Sep 2019 20:56:41 +1000 Subject: [PATCH] Fix client global options --- client/client.go | 2 +- client/client_test.go | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/client/client.go b/client/client.go index 903e26cef48..64367931e9f 100644 --- a/client/client.go +++ b/client/client.go @@ -111,7 +111,7 @@ func (p *Client) newRequest(query string, options ...Option) (*http.Request, err bd.HTTP.Header.Set("Content-Type", "application/json") // per client options from client.New apply first - for _, option := range options { + for _, option := range p.opts { option(bd) } // per request options diff --git a/client/client_test.go b/client/client_test.go index 98d907e5c11..64a75a30c6a 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -54,6 +54,19 @@ func TestAddHeader(t *testing.T) { ) } +func TestAddClientHeader(t *testing.T) { + h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + require.Equal(t, "ASDF", r.Header.Get("Test-Key")) + + w.Write([]byte(`{}`)) + }) + + c := client.New(h, client.AddHeader("Test-Key", "ASDF")) + + var resp struct{} + c.MustPost("{ id }", &resp) +} + func TestBasicAuth(t *testing.T) { h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { user, pass, ok := r.BasicAuth()