diff --git a/api/api.go b/api/api.go index f291ad78e7..7d7e1061d3 100644 --- a/api/api.go +++ b/api/api.go @@ -348,9 +348,11 @@ func NewClient(config *Config) (*Client, error) { parts := strings.SplitN(config.Address, "://", 2) if len(parts) == 2 { - if parts[0] == "https" { + switch parts[0] { + case "http": + case "https": config.Scheme = "https" - } else if parts[0] == "unix" { + case "unix": trans := cleanhttp.DefaultTransport() trans.Dial = func(_, _ string) (net.Conn, error) { return net.Dial("unix", parts[1]) @@ -358,6 +360,8 @@ func NewClient(config *Config) (*Client, error) { config.HttpClient = &http.Client{ Transport: trans, } + default: + return nil, fmt.Errorf("Unknown protocol scheme: %s", parts[0]) } config.Address = parts[1] } diff --git a/command/agent/command.go b/command/agent/command.go index 8f9a8712f6..921aea2fc9 100644 --- a/command/agent/command.go +++ b/command/agent/command.go @@ -1086,8 +1086,11 @@ func (c *Command) Run(args []string) int { var err error if config.Ports.HTTP != -1 { httpAddr, err = config.ClientListener(config.Addresses.HTTP, config.Ports.HTTP) - } else { + } else if config.Ports.HTTPS != -1 { httpAddr, err = config.ClientListener(config.Addresses.HTTPS, config.Ports.HTTPS) + } else if len(config.WatchPlans) > 0 { + c.Ui.Error("Error: cannot use watches if both HTTP and HTTPS are disabled") + return 1 } if err != nil { c.Ui.Error(fmt.Sprintf("Failed to determine HTTP address: %v", err)) diff --git a/website/source/docs/commands/_http_api_options_client.html.markdown b/website/source/docs/commands/_http_api_options_client.html.markdown index ccdf5176b7..8e5f443eb1 100644 --- a/website/source/docs/commands/_http_api_options_client.html.markdown +++ b/website/source/docs/commands/_http_api_options_client.html.markdown @@ -1,7 +1,9 @@ * `-http-addr=` - Address of the Consul agent with the port. This can be an IP address or DNS address, but it must include the port. This can also be - specified via the `CONSUL_HTTP_ADDR` environment variable. The default value is - 127.0.0.1:8500. + specified via the `CONSUL_HTTP_ADDR` environment variable. In Consul 0.8 and + later, the default value is http://127.0.0.1:8500, and https can optionally + be used instead. The scheme can also be set to HTTPS by setting the + environment variable `CONSUL_HTTP_SSL=true`. * `-token=` - ACL token to use in the request. This can also be specified via the `CONSUL_HTTP_TOKEN` environment variable. If unspecified, the query