Skip to content

Commit

Permalink
improved override header handling (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevatkm authored Feb 7, 2018
1 parent d106797 commit 09f1952
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ func parseRequestHeader(c *Client, r *Request) error {
for k := range c.Header {
hdr[k] = append(hdr[k], c.Header[k]...)
}

for k := range r.Header {
hdr.Del(k)
hdr[k] = append(hdr[k], r.Header[k]...)
}

Expand Down
17 changes: 17 additions & 0 deletions request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1277,3 +1277,20 @@ func TestRequestQueryStringOrder(t *testing.T) {

logResponse(t, resp)
}

func TestRequestOverridesClientAuthorizationHeader(t *testing.T) {
ts := createAuthServer(t)
defer ts.Close()

c := dc()
c.SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true}).
SetHeader("Authorization", "some token")
SetHostURL(ts.URL + "/")

resp, err := c.R().
SetHeader("Authorization", "Bearer 004DDB79-6801-4587-B976-F093E6AC44FF").
Get("/profile")

assertError(t, err)
assertEqual(t, http.StatusOK, resp.StatusCode())
}

0 comments on commit 09f1952

Please sign in to comment.