Feature: add default hosts localhost
This commit is contained in:
parent
2dece02df6
commit
fb628e9c62
3 changed files with 14 additions and 1 deletions
|
@ -30,9 +30,13 @@ func validAndSplitDomain(domain string) ([]string, bool) {
|
|||
|
||||
parts := strings.Split(domain, domainStep)
|
||||
if len(parts) == 1 {
|
||||
if parts[0] == "" {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
return parts, true
|
||||
}
|
||||
|
||||
for _, part := range parts[1:] {
|
||||
if part == "" {
|
||||
return nil, false
|
||||
|
|
|
@ -14,6 +14,7 @@ func TestTrie_Basic(t *testing.T) {
|
|||
domains := []string{
|
||||
"example.com",
|
||||
"google.com",
|
||||
"localhost",
|
||||
}
|
||||
|
||||
for _, domain := range domains {
|
||||
|
@ -24,6 +25,8 @@ func TestTrie_Basic(t *testing.T) {
|
|||
assert.NotNil(t, node)
|
||||
assert.True(t, node.Data.(net.IP).Equal(localIP))
|
||||
assert.NotNil(t, tree.Insert("", localIP))
|
||||
assert.Nil(t, tree.Search(""))
|
||||
assert.NotNil(t, tree.Search("localhost"))
|
||||
}
|
||||
|
||||
func TestTrie_Wildcard(t *testing.T) {
|
||||
|
|
|
@ -418,6 +418,12 @@ func parseRules(cfg *RawConfig, proxies map[string]C.Proxy) ([]C.Rule, error) {
|
|||
|
||||
func parseHosts(cfg *RawConfig) (*trie.DomainTrie, error) {
|
||||
tree := trie.New()
|
||||
|
||||
// add default hosts
|
||||
if err := tree.Insert("localhost", net.IP{127, 0, 0, 1}); err != nil {
|
||||
println(err.Error())
|
||||
}
|
||||
|
||||
if len(cfg.Hosts) != 0 {
|
||||
for domain, ipStr := range cfg.Hosts {
|
||||
ip := net.ParseIP(ipStr)
|
||||
|
|
Loading…
Reference in a new issue