mirror of
https://github.com/apernet/hysteria.git
synced 2025-04-03 20:47:38 +03:00
chore: a better approach for http proxy error log
This commit is contained in:
parent
2fb70bdb58
commit
f7de18fd43
1 changed files with 11 additions and 23 deletions
|
@ -27,7 +27,12 @@ func NewProxyHTTPServer(hyClient *core.Client, transport *transport.ClientTransp
|
|||
proxy.Logger = &nopLogger{}
|
||||
proxy.NonproxyHandler = http.NotFoundHandler()
|
||||
proxy.Tr = &http.Transport{
|
||||
Dial: func(network, addr string) (net.Conn, error) {
|
||||
Dial: func(network, addr string) (conn net.Conn, err error) {
|
||||
defer func() {
|
||||
if err != nil {
|
||||
proxyErrorFunc(addr, err)
|
||||
}
|
||||
}()
|
||||
// Parse addr string
|
||||
host, port, err := utils.SplitHostPort(addr)
|
||||
if err != nil {
|
||||
|
@ -48,44 +53,27 @@ func NewProxyHTTPServer(hyClient *core.Client, transport *transport.ClientTransp
|
|||
if resErr != nil {
|
||||
return nil, resErr
|
||||
}
|
||||
conn, err := transport.DialTCP(&net.TCPAddr{
|
||||
return transport.DialTCP(&net.TCPAddr{
|
||||
IP: ipAddr.IP,
|
||||
Port: int(port),
|
||||
Zone: ipAddr.Zone,
|
||||
})
|
||||
if err != nil {
|
||||
proxyErrorFunc(addr, err)
|
||||
}
|
||||
return conn, err
|
||||
case acl.ActionProxy:
|
||||
conn, err := hyClient.DialTCP(addr)
|
||||
if err != nil {
|
||||
proxyErrorFunc(addr, err)
|
||||
}
|
||||
return conn, err
|
||||
return hyClient.DialTCP(addr)
|
||||
case acl.ActionBlock:
|
||||
err := errors.New("blocked by ACL")
|
||||
proxyErrorFunc(addr, err)
|
||||
return nil, err
|
||||
return nil, errors.New("blocked by ACL")
|
||||
case acl.ActionHijack:
|
||||
hijackIPAddr, err := transport.ResolveIPAddr(arg)
|
||||
if err != nil {
|
||||
proxyErrorFunc(addr, err)
|
||||
return nil, err
|
||||
}
|
||||
conn, err := transport.DialTCP(&net.TCPAddr{
|
||||
return transport.DialTCP(&net.TCPAddr{
|
||||
IP: hijackIPAddr.IP,
|
||||
Port: int(port),
|
||||
Zone: hijackIPAddr.Zone,
|
||||
})
|
||||
if err != nil {
|
||||
proxyErrorFunc(addr, err)
|
||||
}
|
||||
return conn, err
|
||||
default:
|
||||
err := fmt.Errorf("unknown action %d", action)
|
||||
proxyErrorFunc(addr, err)
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("unknown action %d", action)
|
||||
}
|
||||
},
|
||||
IdleConnTimeout: idleTimeout,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue