Skip to content

Commit

Permalink
Merge pull request #875 from 99designs/fix-clientwide-opts
Browse files Browse the repository at this point in the history
Fix client global options
  • Loading branch information
vektah authored Sep 24, 2019
2 parents b43edf5 + 921aa9c commit 0bc3cc8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 0bc3cc8

Please sign in to comment.