forked from lqqyt2423/go-mitmproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support ignore_hosts allow_hosts options
- Loading branch information
Showing
4 changed files
with
118 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
) | ||
|
||
func loadConfig() *Config { | ||
config := new(Config) | ||
|
||
flag.IntVar(&config.debug, "debug", 0, "debug mode: 1 - print debug log, 2 - show debug from") | ||
flag.BoolVar(&config.version, "version", false, "show version") | ||
flag.StringVar(&config.addr, "addr", ":9080", "proxy listen addr") | ||
flag.StringVar(&config.webAddr, "web_addr", ":9081", "web interface listen addr") | ||
flag.BoolVar(&config.ssl_insecure, "ssl_insecure", false, "not verify upstream server SSL/TLS certificates.") | ||
flag.StringVar(&config.dump, "dump", "", "dump filename") | ||
flag.IntVar(&config.dumpLevel, "dump_level", 0, "dump level: 0 - header, 1 - header + body") | ||
flag.StringVar(&config.mapperDir, "mapper_dir", "", "mapper files dirpath") | ||
flag.StringVar(&config.certPath, "cert_path", "", "path of generate cert files") | ||
flag.Var((*arrayValue)(&config.ignoreHosts), "ignore_hosts", "a list of ignore hosts") | ||
flag.Var((*arrayValue)(&config.allowHosts), "allow_hosts", "a list of allow hosts") | ||
flag.Parse() | ||
|
||
return config | ||
} | ||
|
||
// arrayValue 实现了 flag.Value 接口 | ||
type arrayValue []string | ||
|
||
func (a *arrayValue) String() string { | ||
return fmt.Sprint(*a) | ||
} | ||
|
||
func (a *arrayValue) Set(value string) error { | ||
*a = append(*a, value) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestMatchHost(t *testing.T) { | ||
address := "www.baidu.com:443" | ||
hosts := []string{ | ||
"www.baidu.com:443", | ||
"www.baidu.com", | ||
"www.google.com", | ||
} | ||
expected := true | ||
result := matchHost(address, hosts) | ||
if result != expected { | ||
t.Errorf("Expected %t but got %t", expected, result) | ||
} | ||
|
||
address = "www.google.com:80" | ||
hosts = []string{ | ||
"www.baidu.com:443", | ||
"www.baidu.com", | ||
"www.google.com", | ||
} | ||
expected = true | ||
result = matchHost(address, hosts) | ||
if result != expected { | ||
t.Errorf("Expected %t but got %t", expected, result) | ||
} | ||
|
||
address = "www.test.com:80" | ||
hosts = []string{ | ||
"www.baidu.com:443", | ||
"www.baidu.com", | ||
"www.google.com", | ||
} | ||
expected = false | ||
result = matchHost(address, hosts) | ||
if result != expected { | ||
t.Errorf("Expected %t but got %t", expected, result) | ||
} | ||
} |