HCPCP-1619: allow unix socket path to the host

pull/21215/head
cskh 6 months ago
parent 574f53d176
commit e2930c00bd

@ -368,6 +368,9 @@ type Config struct {
// HttpAuth is the auth info to use for http access.
HttpAuth *HttpBasicAuth
// HostOverride is the override to host. Default is Address.
HostOverride string
// WaitTime limits how long a Watch will block. If not provided,
// the agent default values will be used.
WaitTime time.Duration
@ -1029,6 +1032,9 @@ func (r *request) toHTTP() (*http.Request, error) {
req.URL.Host = r.url.Host
req.URL.Scheme = r.url.Scheme
req.Host = r.url.Host
if r.config.HostOverride != "" {
req.Host = r.config.HostOverride
}
req.Header = r.header
// Content-Type must always be set when a body is present

@ -994,6 +994,22 @@ func TestAPI_RequestToHTTP(t *testing.T) {
}
}
func TestAPI_RequestToHTTP_HostOverride(t *testing.T) {
t.Parallel()
c, s := makeClient(t)
defer s.Stop()
r := c.newRequest("DELETE", "/v1/kv/foo")
q := &QueryOptions{
Datacenter: "foo",
}
r.setQueryOptions(q)
r.config.HostOverride = "https.consul.unix.socket"
req, err := r.toHTTP()
require.NoError(t, err)
require.Equal(t, "https.consul.unix.socket", req.Host)
}
func TestAPI_ParseQueryMeta(t *testing.T) {
t.Parallel()
resp := &http.Response{

Loading…
Cancel
Save