Skip to content

Commit

Permalink
Support multiple headers, drop canonicalize names when not needed
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Pivotto <roidelapluie@o11y.eu>
  • Loading branch information
roidelapluie committed Dec 8, 2022
1 parent 59a1d6d commit a7c7b9d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
30 changes: 30 additions & 0 deletions config/http_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1680,3 +1680,33 @@ func TestHeaders(t *testing.T) {
t.Fatalf("can't fetch URL: %v", err)
}
}

func TestMultipleHeaders(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
for k, v := range map[string][]string{
"One": {"value1a", "value1b", "value1c"},
"Two": {"value2a", "value2b", "value2c"},
"Three": {"value3a", "value3b", "value3c"},
} {
if !reflect.DeepEqual(r.Header.Values(k), v) {
t.Errorf("expected %v, got %v", v, r.Header.Values(k))
}
}
w.WriteHeader(http.StatusNoContent)
}))
t.Cleanup(ts.Close)

cfg, _, err := LoadHTTPConfigFile("testdata/http.conf.headers-multiple.good.yaml")
if err != nil {
t.Fatalf("Error loading HTTP client config: %v", err)
}
client, err := NewClientFromConfig(*cfg, "test")
if err != nil {
t.Fatalf("Error creating HTTP Client: %v", err)
}

_, err = client.Get(ts.URL)
if err != nil {
t.Fatalf("can't fetch URL: %v", err)
}
}
3 changes: 3 additions & 0 deletions config/testdata/headers-file-a
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
value3a


1 change: 1 addition & 0 deletions config/testdata/headers-file-b
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
value3b
1 change: 1 addition & 0 deletions config/testdata/headers-file-c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
value3c

0 comments on commit a7c7b9d

Please sign in to comment.