Signed-off-by: arraykeys@gmail.com <arraykeys@gmail.com>
This commit is contained in:
@ -1,6 +1,9 @@
|
|||||||
proxy更新日志
|
proxy更新日志
|
||||||
v4.1
|
v4.1
|
||||||
1.优化了http(s),socks5代理中的域名智能判断,如果是内网IP,直接走本地网络,提升浏览体验.
|
1.优化了http(s),socks5代理中的域名智能判断,如果是内网IP,直接走本地网络,提升浏览体验,
|
||||||
|
同时优化了检查机制,判断更快.
|
||||||
|
2.http代理basic认证增加了对https协议的支持,现在basic认证可以控制所有http(s)流量了.
|
||||||
|
|
||||||
|
|
||||||
v4.0
|
v4.0
|
||||||
1.内网穿透三端重构了一个multiplexing版本,使用github.com/xtaci/smux实现了tcp链接的多路复用,
|
1.内网穿透三端重构了一个multiplexing版本,使用github.com/xtaci/smux实现了tcp链接的多路复用,
|
||||||
|
|||||||
@ -161,11 +161,7 @@ func (s *HTTP) callback(inConn net.Conn) {
|
|||||||
} else if *s.cfg.Always {
|
} else if *s.cfg.Always {
|
||||||
useProxy = true
|
useProxy = true
|
||||||
} else {
|
} else {
|
||||||
if req.IsHTTPS() {
|
s.checker.Add(address)
|
||||||
s.checker.Add(address, true, req.Method, "", nil)
|
|
||||||
} else {
|
|
||||||
s.checker.Add(address, false, req.Method, req.URL, req.HeadBuf)
|
|
||||||
}
|
|
||||||
//var n, m uint
|
//var n, m uint
|
||||||
useProxy, _, _ = s.checker.IsBlocked(req.Host)
|
useProxy, _, _ = s.checker.IsBlocked(req.Host)
|
||||||
//log.Printf("blocked ? : %v, %s , fail:%d ,success:%d", useProxy, address, n, m)
|
//log.Printf("blocked ? : %v, %s , fail:%d ,success:%d", useProxy, address, n, m)
|
||||||
|
|||||||
@ -421,7 +421,7 @@ func (s *Socks) proxyTCP(inConn *net.Conn, methodReq socks.MethodsRequest, reque
|
|||||||
if utils.IsIternalIP(host) {
|
if utils.IsIternalIP(host) {
|
||||||
useProxy = false
|
useProxy = false
|
||||||
} else {
|
} else {
|
||||||
s.checker.Add(request.Addr(), true, "", "", nil)
|
s.checker.Add(request.Addr())
|
||||||
useProxy, _, _ = s.checker.IsBlocked(request.Addr())
|
useProxy, _, _ = s.checker.IsBlocked(request.Addr())
|
||||||
}
|
}
|
||||||
if useProxy {
|
if useProxy {
|
||||||
|
|||||||
@ -74,22 +74,20 @@ func (c *Checker) loadMap(f string) (dataMap ConcurrentMap) {
|
|||||||
}
|
}
|
||||||
func (c *Checker) start() {
|
func (c *Checker) start() {
|
||||||
go func() {
|
go func() {
|
||||||
|
//log.Printf("checker started")
|
||||||
for {
|
for {
|
||||||
|
//log.Printf("checker did")
|
||||||
for _, v := range c.data.Items() {
|
for _, v := range c.data.Items() {
|
||||||
go func(item CheckerItem) {
|
go func(item CheckerItem) {
|
||||||
if c.isNeedCheck(item) {
|
if c.isNeedCheck(item) {
|
||||||
//log.Printf("check %s", item.Domain)
|
//log.Printf("check %s", item.Host)
|
||||||
var conn net.Conn
|
var conn net.Conn
|
||||||
var err error
|
var err error
|
||||||
if item.IsHTTPS {
|
|
||||||
conn, err = ConnectHost(item.Host, c.timeout)
|
conn, err = ConnectHost(item.Host, c.timeout)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
conn.SetDeadline(time.Now().Add(time.Millisecond))
|
conn.SetDeadline(time.Now().Add(time.Millisecond))
|
||||||
conn.Close()
|
conn.Close()
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
err = HTTPGet(item.URL, c.timeout)
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
item.FailCount = item.FailCount + 1
|
item.FailCount = item.FailCount + 1
|
||||||
} else {
|
} else {
|
||||||
@ -155,22 +153,13 @@ func (c *Checker) domainIsInMap(address string, blockedMap bool) bool {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
func (c *Checker) Add(address string, isHTTPS bool, method, URL string, data []byte) {
|
func (c *Checker) Add(address string) {
|
||||||
if c.domainIsInMap(address, false) || c.domainIsInMap(address, true) {
|
if c.domainIsInMap(address, false) || c.domainIsInMap(address, true) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !isHTTPS && strings.ToLower(method) != "get" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var item CheckerItem
|
var item CheckerItem
|
||||||
u := strings.Split(address, ":")
|
|
||||||
item = CheckerItem{
|
item = CheckerItem{
|
||||||
URL: URL,
|
|
||||||
Domain: u[0],
|
|
||||||
Host: address,
|
Host: address,
|
||||||
Data: data,
|
|
||||||
IsHTTPS: isHTTPS,
|
|
||||||
Method: method,
|
|
||||||
}
|
}
|
||||||
c.data.SetIfAbsent(item.Host, item)
|
c.data.SetIfAbsent(item.Host, item)
|
||||||
}
|
}
|
||||||
@ -361,6 +350,12 @@ func (req *HTTPRequest) HTTP() (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
func (req *HTTPRequest) HTTPS() (err error) {
|
func (req *HTTPRequest) HTTPS() (err error) {
|
||||||
|
if req.isBasicAuth {
|
||||||
|
err = req.BasicAuth()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
req.Host = req.hostOrURL
|
req.Host = req.hostOrURL
|
||||||
req.addPortIfNot()
|
req.addPortIfNot()
|
||||||
//_, err = fmt.Fprint(*req.conn, "HTTP/1.1 200 Connection established\r\n\r\n")
|
//_, err = fmt.Fprint(*req.conn, "HTTP/1.1 200 Connection established\r\n\r\n")
|
||||||
@ -376,7 +371,8 @@ func (req *HTTPRequest) IsHTTPS() bool {
|
|||||||
|
|
||||||
func (req *HTTPRequest) BasicAuth() (err error) {
|
func (req *HTTPRequest) BasicAuth() (err error) {
|
||||||
|
|
||||||
//log.Printf("request :%s", string(b[:n]))
|
//log.Printf("request :%s", string(b[:n]))authorization
|
||||||
|
isProxyAuthorization := false
|
||||||
authorization, err := req.getHeader("Authorization")
|
authorization, err := req.getHeader("Authorization")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprint((*req.conn), "HTTP/1.1 401 Unauthorized\r\nWWW-Authenticate: Basic realm=\"\"\r\n\r\nUnauthorized")
|
fmt.Fprint((*req.conn), "HTTP/1.1 401 Unauthorized\r\nWWW-Authenticate: Basic realm=\"\"\r\n\r\nUnauthorized")
|
||||||
@ -386,10 +382,11 @@ func (req *HTTPRequest) BasicAuth() (err error) {
|
|||||||
if authorization == "" {
|
if authorization == "" {
|
||||||
authorization, err = req.getHeader("Proxy-Authorization")
|
authorization, err = req.getHeader("Proxy-Authorization")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprint((*req.conn), "HTTP/1.1 401 Unauthorized\r\nWWW-Authenticate: Basic realm=\"\"\r\n\r\nUnauthorized")
|
fmt.Fprint((*req.conn), "HTTP/1.1 407 Unauthorized\r\nWWW-Authenticate: Basic realm=\"\"\r\n\r\nUnauthorized")
|
||||||
CloseConn(req.conn)
|
CloseConn(req.conn)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
isProxyAuthorization = true
|
||||||
}
|
}
|
||||||
//log.Printf("Authorization:%s", authorization)
|
//log.Printf("Authorization:%s", authorization)
|
||||||
basic := strings.Fields(authorization)
|
basic := strings.Fields(authorization)
|
||||||
@ -414,7 +411,11 @@ func (req *HTTPRequest) BasicAuth() (err error) {
|
|||||||
authOk := (*req.basicAuth).Check(string(user), addr[0], URL)
|
authOk := (*req.basicAuth).Check(string(user), addr[0], URL)
|
||||||
//log.Printf("auth %s,%v", string(user), authOk)
|
//log.Printf("auth %s,%v", string(user), authOk)
|
||||||
if !authOk {
|
if !authOk {
|
||||||
fmt.Fprint((*req.conn), "HTTP/1.1 401 Unauthorized\r\n\r\nUnauthorized")
|
code := "401"
|
||||||
|
if isProxyAuthorization {
|
||||||
|
code = "407"
|
||||||
|
}
|
||||||
|
fmt.Fprintf((*req.conn), "HTTP/1.1 %s Unauthorized\r\n\r\nUnauthorized", code)
|
||||||
CloseConn(req.conn)
|
CloseConn(req.conn)
|
||||||
err = fmt.Errorf("basic auth fail")
|
err = fmt.Errorf("basic auth fail")
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user