Skip to content

Commit

Permalink
HCPCP-1619: allow unix socket path to the host
Browse files Browse the repository at this point in the history
  • Loading branch information
huikang committed May 23, 2024
1 parent 574f53d commit e2930c0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit e2930c0

Please sign in to comment.