Skip to content

Commit

Permalink
hotfix: use header.Set instead of header.Add
Browse files Browse the repository at this point in the history
  • Loading branch information
strider2038 committed Jan 29, 2024
1 parent 0a7acfb commit 9bd449f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions apitest/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ import (
// RequestOption can be used to tune up http.Request.
type RequestOption func(r *http.Request)

// WithHeader option adds specific header to the request.
// WithHeader option overrides specific header to the request.
func WithHeader(key, value string) RequestOption {
return func(r *http.Request) {
r.Header.Add(key, value)
r.Header.Set(key, value)
}
}

// WithContentType option adds Content-Type header to the request.
// WithContentType option overrides Content-Type header to the request.
func WithContentType(contentType string) RequestOption {
return func(r *http.Request) {
r.Header.Add("Content-Type", contentType)
r.Header.Set("Content-Type", contentType)
}
}

// WithJSONContentType option adds Content-Type header to the request
// WithJSONContentType option overrides Content-Type header to the request
// with "application/json" content type.
func WithJSONContentType() RequestOption {
return func(r *http.Request) {
r.Header.Add("Content-Type", "application/json; charset=utf-8")
r.Header.Set("Content-Type", "application/json; charset=utf-8")
}
}

Expand Down
2 changes: 1 addition & 1 deletion apitest/handle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestHandleRequest(t *testing.T) {
t.Helper()
assert.Equal(t, http.MethodGet, request.Method)
assert.Equal(t, testURL, request.URL.String())
assert.Equal(t, []string{"foo", "bar"}, request.Header["X-Test"])
assert.Equal(t, []string{"bar"}, request.Header["X-Test"])
},
},
{
Expand Down

0 comments on commit 9bd449f

Please sign in to comment.