chore: share some code
This commit is contained in:
@ -12,7 +12,7 @@ import (
|
||||
"github.com/Dreamacro/clash/transport/socks5"
|
||||
)
|
||||
|
||||
func newClient(source net.Addr, tunnel C.Tunnel, additions ...inbound.Addition) *http.Client {
|
||||
func newClient(srcConn net.Conn, tunnel C.Tunnel, additions ...inbound.Addition) *http.Client {
|
||||
return &http.Client{
|
||||
Transport: &http.Transport{
|
||||
// from http.DefaultTransport
|
||||
@ -32,7 +32,7 @@ func newClient(source net.Addr, tunnel C.Tunnel, additions ...inbound.Addition)
|
||||
|
||||
left, right := net.Pipe()
|
||||
|
||||
go tunnel.HandleTCPConn(inbound.NewHTTP(dstAddr, source, right, additions...))
|
||||
go tunnel.HandleTCPConn(inbound.NewHTTP(dstAddr, srcConn, right, additions...))
|
||||
|
||||
return left, nil
|
||||
},
|
||||
|
@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
func HandleConn(c net.Conn, tunnel C.Tunnel, cache *cache.LruCache[string, bool], additions ...inbound.Addition) {
|
||||
client := newClient(c.RemoteAddr(), tunnel, additions...)
|
||||
client := newClient(c, tunnel, additions...)
|
||||
defer client.CloseIdleConnections()
|
||||
|
||||
conn := N.NewBufferedConn(c)
|
||||
|
@ -43,7 +43,7 @@ func handleUpgrade(conn net.Conn, request *http.Request, tunnel C.Tunnel, additi
|
||||
|
||||
left, right := net.Pipe()
|
||||
|
||||
go tunnel.HandleTCPConn(inbound.NewHTTP(dstAddr, conn.RemoteAddr(), right, additions...))
|
||||
go tunnel.HandleTCPConn(inbound.NewHTTP(dstAddr, conn, right, additions...))
|
||||
|
||||
var bufferedLeft *N.BufferedConn
|
||||
if request.TLS != nil {
|
||||
|
Reference in New Issue
Block a user