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"
|
"hash/fnv"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/cenkalti/backoff/v4"
|
"github.com/cenkalti/backoff/v4"
|
||||||
|
@ -149,7 +150,11 @@ func (p *Provider) fetchConfigurationData() ([]byte, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range p.Headers {
|
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)
|
res, err := p.httpClient.Do(req)
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -85,8 +86,9 @@ func TestProvider_fetchConfigurationData(t *testing.T) {
|
||||||
desc: "should send configured headers",
|
desc: "should send configured headers",
|
||||||
statusCode: http.StatusOK,
|
statusCode: http.StatusOK,
|
||||||
headers: map[string]string{
|
headers: map[string]string{
|
||||||
"Foo": "bar",
|
"Foo": "bar",
|
||||||
"Bar": "baz",
|
"Bar": "baz",
|
||||||
|
"Host": "localhost",
|
||||||
},
|
},
|
||||||
expData: []byte("{}"),
|
expData: []byte("{}"),
|
||||||
expErr: require.NoError,
|
expErr: require.NoError,
|
||||||
|
@ -105,7 +107,11 @@ func TestProvider_fetchConfigurationData(t *testing.T) {
|
||||||
handlerCalled = true
|
handlerCalled = true
|
||||||
|
|
||||||
for k, v := range test.headers {
|
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)
|
rw.WriteHeader(test.statusCode)
|
||||||
|
|
Loading…
Reference in a new issue