Skip to content

Commit

Permalink
Support ipv6 proxy address
Browse files Browse the repository at this point in the history
  • Loading branch information
alanhamlett committed Aug 14, 2023
1 parent abd1cc8 commit cfcbf4a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cmd/params/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ var (
// nolint
apiKeyRegex = regexp.MustCompile("^(waka_)?[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$")
// nolint
ipv6ProxyRegex = regexp.MustCompile(`^((https?|socks5)://)?([^:@]+(:([^:@])+)?@)?(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))(:\d+)?$`)
// nolint
matchAllRegex = regexp.MustCompile(".*")
// nolint
matchNoneRegex = regexp.MustCompile("a^")
Expand Down Expand Up @@ -273,7 +275,9 @@ func LoadAPIParams(v *viper.Viper) (API, error) {
}

if proxyURL != "" && !rgx.MatchString(proxyURL) {
return API{}, api.ErrAuth{Err: fmt.Errorf(errMsgTemplate, proxyURL)}
if !ipv6ProxyRegex.MatchString(proxyURL) {
return API{}, api.ErrAuth{Err: fmt.Errorf(errMsgTemplate, proxyURL)}
}
}

proxyEnv := httpproxy.FromEnvironment()
Expand Down
1 change: 1 addition & 0 deletions cmd/params/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2012,6 +2012,7 @@ func TestLoad_API_ProxyURL(t *testing.T) {
"https": "https://john:[email protected]:8888",
"http": "http://john:[email protected]:8888",
"socks5": "socks5://john:[email protected]:8888",
"ipv6": "socks5://john:secret@2001:0db8:85a3:0000:0000:8a2e:0370:7334:8888",

Check failure on line 2015 in cmd/params/params_test.go

View workflow job for this annotation

GitHub Actions / Unit Tests

File is not `gofmt`-ed with `-s` (gofmt)

Check failure on line 2015 in cmd/params/params_test.go

View workflow job for this annotation

GitHub Actions / Unit Tests macOS

File is not `gofmt`-ed with `-s` (gofmt)
"ntlm": `domain\\john:123456`,
}

Expand Down

0 comments on commit cfcbf4a

Please sign in to comment.