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,8 +150,12 @@ func (p *Provider) fetchConfigurationData() ([]byte, error) {
|
|||
}
|
||||
|
||||
for k, v := range p.Headers {
|
||||
if strings.EqualFold(k, "Host") {
|
||||
req.Host = v
|
||||
} else {
|
||||
req.Header.Set(k, v)
|
||||
}
|
||||
}
|
||||
|
||||
res, err := p.httpClient.Do(req)
|
||||
if err != nil {
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -87,6 +88,7 @@ func TestProvider_fetchConfigurationData(t *testing.T) {
|
|||
headers: map[string]string{
|
||||
"Foo": "bar",
|
||||
"Bar": "baz",
|
||||
"Host": "localhost",
|
||||
},
|
||||
expData: []byte("{}"),
|
||||
expErr: require.NoError,
|
||||
|
@ -105,8 +107,12 @@ func TestProvider_fetchConfigurationData(t *testing.T) {
|
|||
handlerCalled = true
|
||||
|
||||
for k, v := range test.headers {
|
||||
if strings.EqualFold(k, "Host") {
|
||||
assert.Equal(t, v, req.Host)
|
||||
} else {
|
||||
assert.Equal(t, v, req.Header.Get(k))
|
||||
}
|
||||
}
|
||||
|
||||
rw.WriteHeader(test.statusCode)
|
||||
_, _ = rw.Write([]byte("{}"))
|
||||
|
|
Loading…
Reference in a new issue