0
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2024-12-23 22:27:38 -05:00

If scheme and port defy convention, it is an error

This prevents serving HTTPS over port 80 or HTTP over 443. It's confusing and we don't allow it.
This commit is contained in:
Matthew Holt 2016-01-10 20:51:50 -07:00
parent 202849055c
commit ed0c0db6a3
2 changed files with 8 additions and 1 deletions

View file

@ -338,7 +338,12 @@ func standardAddress(str string) (address, error) {
// repeated or conflicting scheme is confusing, so error
if scheme != "" && (port == "http" || port == "https") {
return address{}, fmt.Errorf("[%s] scheme specified twice in address", str)
return address{}, fmt.Errorf("[%s] scheme specified twice in address", input)
}
// error if scheme and port combination violate convention
if (scheme == "http" && port == "443") || (scheme == "https" && port == "80") {
return address{}, fmt.Errorf("[%s] scheme and port violate convention", input)
}
// standardize http and https ports to their respective port numbers

View file

@ -27,6 +27,8 @@ func TestStandardAddress(t *testing.T) {
{`:https`, "https", "", "443", false},
{`http://localhost:https`, "", "", "", true}, // conflict
{`http://localhost:http`, "", "", "", true}, // repeated scheme
{`http://localhost:443`, "", "", "", true}, // not conventional
{`https://localhost:80`, "", "", "", true}, // not conventional
{`http://localhost`, "http", "localhost", "80", false},
{`https://localhost`, "https", "localhost", "443", false},
{`http://127.0.0.1`, "http", "127.0.0.1", "80", false},