mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-06 22:40:31 -05:00
Revert "bind: support multiple values (#2128)"
This reverts commit 3a810c6502
.
This commit is contained in:
parent
3a810c6502
commit
b7091650f8
8 changed files with 38 additions and 114 deletions
|
@ -29,17 +29,10 @@ func init() {
|
|||
func setupBind(c *caddy.Controller) error {
|
||||
config := httpserver.GetConfig(c)
|
||||
for c.Next() {
|
||||
args := c.RemainingArgs()
|
||||
|
||||
if len(args) == 0 {
|
||||
return c.Errf("Expected at least one address")
|
||||
if !c.Args(&config.ListenHost) {
|
||||
return c.ArgErr()
|
||||
}
|
||||
|
||||
for _, addr := range args {
|
||||
config.ListenHosts = append(config.ListenHosts, addr)
|
||||
}
|
||||
|
||||
config.TLS.ListenHost = config.ListenHosts[0] // necessary for ACME challenges, see issue #309
|
||||
config.TLS.ListenHost = config.ListenHost // necessary for ACME challenges, see issue #309
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
package bind
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/mholt/caddy"
|
||||
|
@ -23,34 +22,17 @@ import (
|
|||
)
|
||||
|
||||
func TestSetupBind(t *testing.T) {
|
||||
for _, testcase := range []struct {
|
||||
Bind string
|
||||
Hosts []string
|
||||
TLSHost string
|
||||
}{
|
||||
{
|
||||
Bind: "bind 1.2.3.4",
|
||||
Hosts: []string{"1.2.3.4"},
|
||||
TLSHost: "1.2.3.4",
|
||||
},
|
||||
{
|
||||
Bind: "bind 1.2.3.4 5.6.7.8",
|
||||
Hosts: []string{"1.2.3.4", "5.6.7.8"},
|
||||
TLSHost: "1.2.3.4",
|
||||
},
|
||||
} {
|
||||
c := caddy.NewTestController("http", testcase.Bind)
|
||||
err := setupBind(c)
|
||||
if err != nil {
|
||||
t.Fatalf("Expected no errors, but got: %v", err)
|
||||
}
|
||||
c := caddy.NewTestController("http", `bind 1.2.3.4`)
|
||||
err := setupBind(c)
|
||||
if err != nil {
|
||||
t.Fatalf("Expected no errors, but got: %v", err)
|
||||
}
|
||||
|
||||
cfg := httpserver.GetConfig(c)
|
||||
if got, want := cfg.ListenHosts, testcase.Hosts; !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("Expected the config's ListenHost to be %s, was %s", want, got)
|
||||
}
|
||||
if got, want := cfg.TLS.ListenHost, testcase.TLSHost; got != want {
|
||||
t.Errorf("Expected the TLS config's ListenHost to be %s, was %s", want, got)
|
||||
}
|
||||
cfg := httpserver.GetConfig(c)
|
||||
if got, want := cfg.ListenHost, "1.2.3.4"; got != want {
|
||||
t.Errorf("Expected the config's ListenHost to be %s, was %s", want, got)
|
||||
}
|
||||
if got, want := cfg.TLS.ListenHost, "1.2.3.4"; got != want {
|
||||
t.Errorf("Expected the TLS config's ListenHost to be %s, was %s", want, got)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -204,10 +204,10 @@ func redirPlaintextHost(cfg *SiteConfig) *SiteConfig {
|
|||
addr := net.JoinHostPort(host, port)
|
||||
|
||||
return &SiteConfig{
|
||||
Addr: Address{Original: addr, Host: host, Port: port},
|
||||
ListenHosts: cfg.ListenHosts,
|
||||
middleware: []Middleware{redirMiddleware},
|
||||
TLS: &caddytls.Config{AltHTTPPort: cfg.TLS.AltHTTPPort, AltTLSSNIPort: cfg.TLS.AltTLSSNIPort},
|
||||
Timeouts: cfg.Timeouts,
|
||||
Addr: Address{Original: addr, Host: host, Port: port},
|
||||
ListenHost: cfg.ListenHost,
|
||||
middleware: []Middleware{redirMiddleware},
|
||||
TLS: &caddytls.Config{AltHTTPPort: cfg.TLS.AltHTTPPort, AltTLSSNIPort: cfg.TLS.AltTLSSNIPort},
|
||||
Timeouts: cfg.Timeouts,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ import (
|
|||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/mholt/caddy/caddytls"
|
||||
|
@ -29,7 +28,7 @@ func TestRedirPlaintextHost(t *testing.T) {
|
|||
for i, testcase := range []struct {
|
||||
Host string // used for the site config
|
||||
Port string
|
||||
ListenHosts []string
|
||||
ListenHost string
|
||||
RequestHost string // if different from Host
|
||||
}{
|
||||
{
|
||||
|
@ -44,17 +43,13 @@ func TestRedirPlaintextHost(t *testing.T) {
|
|||
Port: "1234",
|
||||
},
|
||||
{
|
||||
Host: "foohost",
|
||||
ListenHosts: []string{"93.184.216.34"},
|
||||
Host: "foohost",
|
||||
ListenHost: "93.184.216.34",
|
||||
},
|
||||
{
|
||||
Host: "foohost",
|
||||
Port: "1234",
|
||||
ListenHosts: []string{"93.184.216.34"},
|
||||
},
|
||||
{
|
||||
Host: "foohost",
|
||||
ListenHosts: []string{"127.0.0.1", "127.0.0.2"},
|
||||
Host: "foohost",
|
||||
Port: "1234",
|
||||
ListenHost: "93.184.216.34",
|
||||
},
|
||||
{
|
||||
Host: "foohost",
|
||||
|
@ -75,15 +70,15 @@ func TestRedirPlaintextHost(t *testing.T) {
|
|||
Host: testcase.Host,
|
||||
Port: testcase.Port,
|
||||
},
|
||||
ListenHosts: testcase.ListenHosts,
|
||||
TLS: new(caddytls.Config),
|
||||
ListenHost: testcase.ListenHost,
|
||||
TLS: new(caddytls.Config),
|
||||
})
|
||||
|
||||
// Check host and port
|
||||
if actual, expected := cfg.Addr.Host, testcase.Host; actual != expected {
|
||||
t.Errorf("Test %d: Expected redir config to have host %s but got %s", i, expected, actual)
|
||||
}
|
||||
if actual, expected := cfg.ListenHosts, testcase.ListenHosts; !reflect.DeepEqual(actual, expected) {
|
||||
if actual, expected := cfg.ListenHost, testcase.ListenHost; actual != expected {
|
||||
t.Errorf("Test %d: Expected redir config to have bindhost %s but got %s", i, expected, actual)
|
||||
}
|
||||
if actual, expected := cfg.Addr.Port, HTTPPort; actual != expected {
|
||||
|
|
|
@ -239,18 +239,9 @@ func (h *httpContext) MakeServers() ([]caddy.Server, error) {
|
|||
// see if all the addresses (both sites and
|
||||
// listeners) are loopback to help us determine
|
||||
// if this is a "production" instance or not
|
||||
for _, listenHost := range cfg.ListenHosts {
|
||||
if !atLeastOneSiteLooksLikeProduction {
|
||||
if !caddy.IsLoopback(cfg.Addr.Host) &&
|
||||
!caddy.IsLoopback(listenHost) &&
|
||||
(caddytls.QualifiesForManagedTLS(cfg) ||
|
||||
caddytls.HostQualifies(cfg.Addr.Host)) {
|
||||
atLeastOneSiteLooksLikeProduction = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if !atLeastOneSiteLooksLikeProduction && len(cfg.ListenHosts) == 0 {
|
||||
if !atLeastOneSiteLooksLikeProduction {
|
||||
if !caddy.IsLoopback(cfg.Addr.Host) &&
|
||||
!caddy.IsLoopback(cfg.ListenHost) &&
|
||||
(caddytls.QualifiesForManagedTLS(cfg) ||
|
||||
caddytls.HostQualifies(cfg.Addr.Host)) {
|
||||
atLeastOneSiteLooksLikeProduction = true
|
||||
|
@ -377,30 +368,19 @@ func groupSiteConfigsByListenAddr(configs []*SiteConfig) (map[string][]*SiteConf
|
|||
|
||||
for _, conf := range configs {
|
||||
// We would add a special case here so that localhost addresses
|
||||
// bind to 127.0.0.1 if conf.ListenHosts is not already set, which
|
||||
// bind to 127.0.0.1 if conf.ListenHost is not already set, which
|
||||
// would prevent outsiders from even connecting; but that was problematic:
|
||||
// https://caddy.community/t/wildcard-virtual-domains-with-wildcard-roots/221/5?u=matt
|
||||
|
||||
if conf.Addr.Port == "" {
|
||||
conf.Addr.Port = Port
|
||||
}
|
||||
|
||||
if len(conf.ListenHosts) == 0 {
|
||||
addr, err := net.ResolveTCPAddr("tcp", net.JoinHostPort("", conf.Addr.Port))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
addrstr := addr.String()
|
||||
groups[addrstr] = append(groups[addrstr], conf)
|
||||
}
|
||||
for _, host := range conf.ListenHosts {
|
||||
addr, err := net.ResolveTCPAddr("tcp", net.JoinHostPort(host, conf.Addr.Port))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
addrstr := addr.String()
|
||||
groups[addrstr] = append(groups[addrstr], conf)
|
||||
addr, err := net.ResolveTCPAddr("tcp", net.JoinHostPort(conf.ListenHost, conf.Addr.Port))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
addrstr := addr.String()
|
||||
groups[addrstr] = append(groups[addrstr], conf)
|
||||
}
|
||||
|
||||
return groups, nil
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
package httpserver
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
|
@ -348,28 +347,3 @@ func TestHideCaddyfile(t *testing.T) {
|
|||
}
|
||||
t.Fatal("Caddyfile missing from HiddenFiles")
|
||||
}
|
||||
|
||||
func TestGroupSiteConfigsByListenAddr(t *testing.T) {
|
||||
cfg := []*SiteConfig{
|
||||
{
|
||||
ListenHosts: []string{"127.0.0.1", "::1"},
|
||||
},
|
||||
{
|
||||
Addr: Address{
|
||||
Port: "80",
|
||||
},
|
||||
},
|
||||
}
|
||||
groups, err := groupSiteConfigsByListenAddr(cfg)
|
||||
if err != nil {
|
||||
t.Fatal("Failed to group SiteConfigs by listen address")
|
||||
}
|
||||
actual := []string{}
|
||||
for k := range groups {
|
||||
actual = append(actual, k)
|
||||
}
|
||||
expected := []string{"127.0.0.1:" + Port, "[::1]:" + Port, ":80"}
|
||||
if !reflect.DeepEqual(actual, expected) {
|
||||
t.Errorf("Expected listen on %#v, but got %#v", expected, actual)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -419,7 +419,7 @@ func (s *Server) serveHTTP(w http.ResponseWriter, r *http.Request) (int, error)
|
|||
|
||||
// we still check for ACME challenge if the vhost exists,
|
||||
// because we must apply its HTTP challenge config settings
|
||||
if caddytls.HTTPChallengeHandler(w, r, vhost.ListenHosts[0]) {
|
||||
if caddytls.HTTPChallengeHandler(w, r, vhost.ListenHost) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ type SiteConfig struct {
|
|||
|
||||
// The hostname to bind listener to;
|
||||
// defaults to Addr.Host
|
||||
ListenHosts []string
|
||||
ListenHost string
|
||||
|
||||
// TLS configuration
|
||||
TLS *caddytls.Config
|
||||
|
|
Loading…
Reference in a new issue