Commit cc229aef authored by Matthew Holt's avatar Matthew Holt

templates: Parse host successfully when port is implicit (fixes #292)

parent 136119f8
......@@ -97,6 +97,10 @@ func (c Context) URI() string {
func (c Context) Host() (string, error) {
host, _, err := net.SplitHostPort(c.Req.Host)
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 host, nil
......
......@@ -232,8 +232,13 @@ func TestHost(t *testing.T) {
},
{
input: "localhost",
expectedHost: "localhost",
shouldErr: false,
},
{
input: "[::]",
expectedHost: "",
shouldErr: true, // missing port in address
shouldErr: true,
},
}
......@@ -258,6 +263,11 @@ func TestPort(t *testing.T) {
expectedPort: "",
shouldErr: true, // missing port in address
},
{
input: ":8080",
expectedPort: "8080",
shouldErr: false,
},
}
for _, test := range tests {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment