mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
Handle host names case insensitively.
RFC 3986 3.2.2: The host subcomponent is case-insensitive.
This commit is contained in:
parent
e4e773c9ea
commit
497ebb9ccb
3 changed files with 11 additions and 0 deletions
|
@ -104,6 +104,7 @@ func (p *parser) addresses() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
p.block.Addresses = append(p.block.Addresses, addr)
|
p.block.Addresses = append(p.block.Addresses, addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -329,6 +330,9 @@ func standardAddress(str string) (address, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// "The host subcomponent is case-insensitive." (RFC 3986)
|
||||||
|
host = strings.ToLower(host)
|
||||||
|
|
||||||
// see if we can set port based off scheme
|
// see if we can set port based off scheme
|
||||||
if port == "" {
|
if port == "" {
|
||||||
if scheme == "http" {
|
if scheme == "http" {
|
||||||
|
|
|
@ -13,7 +13,9 @@ func TestStandardAddress(t *testing.T) {
|
||||||
shouldErr bool
|
shouldErr bool
|
||||||
}{
|
}{
|
||||||
{`localhost`, "", "localhost", "", false},
|
{`localhost`, "", "localhost", "", false},
|
||||||
|
{`LOCALHOST`, "", "localhost", "", false},
|
||||||
{`localhost:1234`, "", "localhost", "1234", false},
|
{`localhost:1234`, "", "localhost", "1234", false},
|
||||||
|
{`LOCALHOST:1234`, "", "localhost", "1234", false},
|
||||||
{`localhost:`, "", "localhost", "", false},
|
{`localhost:`, "", "localhost", "", false},
|
||||||
{`0.0.0.0`, "", "0.0.0.0", "", false},
|
{`0.0.0.0`, "", "0.0.0.0", "", false},
|
||||||
{`127.0.0.1:1234`, "", "127.0.0.1", "1234", false},
|
{`127.0.0.1:1234`, "", "127.0.0.1", "1234", false},
|
||||||
|
@ -35,6 +37,7 @@ func TestStandardAddress(t *testing.T) {
|
||||||
{`https://127.0.0.1`, "https", "127.0.0.1", "443", false},
|
{`https://127.0.0.1`, "https", "127.0.0.1", "443", false},
|
||||||
{`http://[::1]`, "http", "::1", "80", false},
|
{`http://[::1]`, "http", "::1", "80", false},
|
||||||
{`http://localhost:1234`, "http", "localhost", "1234", false},
|
{`http://localhost:1234`, "http", "localhost", "1234", false},
|
||||||
|
{`http://LOCALHOST:1234`, "http", "localhost", "1234", false},
|
||||||
{`https://127.0.0.1:1234`, "https", "127.0.0.1", "1234", false},
|
{`https://127.0.0.1:1234`, "https", "127.0.0.1", "1234", false},
|
||||||
{`http://[::1]:1234`, "http", "::1", "1234", false},
|
{`http://[::1]:1234`, "http", "::1", "1234", false},
|
||||||
{``, "", "", "", false},
|
{``, "", "", "", false},
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -301,6 +302,9 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
host = r.Host // oh well
|
host = r.Host // oh well
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// "The host subcomponent is case-insensitive." (RFC 3986)
|
||||||
|
host = strings.ToLower(host)
|
||||||
|
|
||||||
// Try the host as given, or try falling back to 0.0.0.0 (wildcard)
|
// Try the host as given, or try falling back to 0.0.0.0 (wildcard)
|
||||||
if _, ok := s.vhosts[host]; !ok {
|
if _, ok := s.vhosts[host]; !ok {
|
||||||
if _, ok2 := s.vhosts["0.0.0.0"]; ok2 {
|
if _, ok2 := s.vhosts["0.0.0.0"]; ok2 {
|
||||||
|
|
Loading…
Reference in a new issue