mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
templates: Parse host successfully when port is implicit (fixes #292)
This commit is contained in:
parent
136119f8ac
commit
cc229aefae
2 changed files with 15 additions and 1 deletions
|
@ -97,6 +97,10 @@ func (c Context) URI() string {
|
||||||
func (c Context) Host() (string, error) {
|
func (c Context) Host() (string, error) {
|
||||||
host, _, err := net.SplitHostPort(c.Req.Host)
|
host, _, err := net.SplitHostPort(c.Req.Host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if !strings.Contains(c.Req.Host, ":") {
|
||||||
|
// common with sites served on the default port 80
|
||||||
|
return c.Req.Host, nil
|
||||||
|
}
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
return host, nil
|
return host, nil
|
||||||
|
|
|
@ -232,8 +232,13 @@ func TestHost(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
input: "localhost",
|
input: "localhost",
|
||||||
|
expectedHost: "localhost",
|
||||||
|
shouldErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: "[::]",
|
||||||
expectedHost: "",
|
expectedHost: "",
|
||||||
shouldErr: true, // missing port in address
|
shouldErr: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,6 +263,11 @@ func TestPort(t *testing.T) {
|
||||||
expectedPort: "",
|
expectedPort: "",
|
||||||
shouldErr: true, // missing port in address
|
shouldErr: true, // missing port in address
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
input: ":8080",
|
||||||
|
expectedPort: "8080",
|
||||||
|
shouldErr: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
|
Loading…
Reference in a new issue