fix(proxy): encode special chars in proxy credentials

This commit is contained in:
luxiang
2026-03-17 08:40:08 +08:00
parent f42c8f2abe
commit 7e34bb946f
2 changed files with 105 additions and 4 deletions

View File

@@ -1,7 +1,9 @@
package service
import (
"fmt"
"net"
"net/url"
"strconv"
"time"
)
@@ -23,10 +25,14 @@ func (p *Proxy) IsActive() bool {
}
func (p *Proxy) URL() string {
if p.Username != "" && p.Password != "" {
return fmt.Sprintf("%s://%s:%s@%s:%d", p.Protocol, p.Username, p.Password, p.Host, p.Port)
u := &url.URL{
Scheme: p.Protocol,
Host: net.JoinHostPort(p.Host, strconv.Itoa(p.Port)),
}
return fmt.Sprintf("%s://%s:%d", p.Protocol, p.Host, p.Port)
if p.Username != "" && p.Password != "" {
u.User = url.UserPassword(p.Username, p.Password)
}
return u.String()
}
type ProxyWithAccountCount struct {