Set Host header in HTTP provider request
This commit is contained in:
parent
7004f0e750
commit
e8ff825ed2
2 changed files with 15 additions and 4 deletions
|
@ -7,6 +7,7 @@ import (
|
|||
"hash/fnv"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/cenkalti/backoff/v4"
|
||||
|
@ -149,7 +150,11 @@ func (p *Provider) fetchConfigurationData() ([]byte, error) {
|
|||
}
|
||||
|
||||
for k, v := range p.Headers {
|
||||
req.Header.Set(k, v)
|
||||
if strings.EqualFold(k, "Host") {
|
||||
req.Host = v
|
||||
} else {
|
||||
req.Header.Set(k, v)
|
||||
}
|
||||
}
|
||||
|
||||
res, err := p.httpClient.Do(req)
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -85,8 +86,9 @@ func TestProvider_fetchConfigurationData(t *testing.T) {
|
|||
desc: "should send configured headers",
|
||||
statusCode: http.StatusOK,
|
||||
headers: map[string]string{
|
||||
"Foo": "bar",
|
||||
"Bar": "baz",
|
||||
"Foo": "bar",
|
||||
"Bar": "baz",
|
||||
"Host": "localhost",
|
||||
},
|
||||
expData: []byte("{}"),
|
||||
expErr: require.NoError,
|
||||
|
@ -105,7 +107,11 @@ func TestProvider_fetchConfigurationData(t *testing.T) {
|
|||
handlerCalled = true
|
||||
|
||||
for k, v := range test.headers {
|
||||
assert.Equal(t, v, req.Header.Get(k))
|
||||
if strings.EqualFold(k, "Host") {
|
||||
assert.Equal(t, v, req.Host)
|
||||
} else {
|
||||
assert.Equal(t, v, req.Header.Get(k))
|
||||
}
|
||||
}
|
||||
|
||||
rw.WriteHeader(test.statusCode)
|
||||
|
|
Loading…
Reference in a new issue