Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: repeated header fields added #12

Merged
merged 1 commit into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pkg/networking/networking.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,14 @@ func (n *NetworkImpl) AddHeaderField(key string, value string) {
}

func (n *NetworkImpl) GetDefaultHeader(url *url.URL) http.Header {
h := n.staticHeader
h := http.Header{}

// add static header
for k, v := range n.staticHeader {
for i := range v {
h.Add(k, v[i])
}
}

if url != nil {
// determine configured api url
Expand Down
20 changes: 12 additions & 8 deletions pkg/networking/networking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ func Test_GetDefaultHeader_WithAuth(t *testing.T) {
"Authorization": {"token " + token},
}

url, _ := url.Parse(config.GetString(configuration.API_URL))
actualHeader := net.GetDefaultHeader(url)

assert.Equal(t, expectedHeader, actualHeader)
// run method under test multiple times to ensure that it behaves the same way each time
for i := 0; i < 3; i++ {
Avishagp marked this conversation as resolved.
Show resolved Hide resolved
url, _ := url.Parse(config.GetString(configuration.API_URL))
actualHeader := net.GetDefaultHeader(url)
assert.Equal(t, expectedHeader, actualHeader)
}
}

func Test_GetDefaultHeader_WithoutAuth(t *testing.T) {
Expand All @@ -47,10 +49,12 @@ func Test_GetDefaultHeader_WithoutAuth(t *testing.T) {
"User-Agent": {defaultUserAgent},
}

url, _ := url.Parse("https://www.myexample.com")
actualHeader := net.GetDefaultHeader(url)

assert.Equal(t, expectedHeader, actualHeader)
// run method under test multiple times to ensure that it behaves the same way each time
for i := 0; i < 3; i++ {
url, _ := url.Parse("https://www.myexample.com")
actualHeader := net.GetDefaultHeader(url)
assert.Equal(t, expectedHeader, actualHeader)
}
}

func Test_Roundtripper_SecureHTTPS(t *testing.T) {
Expand Down