mirror of
https://github.com/cmz0228/hysteria-dev.git
synced 2025-06-29 15:59:58 +00:00
feat: log http proxy error
goproxy actually discard all upstream errors, you can find its error
handling here [1], the upstream error from proxy.connectDial() is always
hidden in the two if branches, and never got logged. we need to log
hysteria layer errors by ourselves.
[1] 8ea89ba920/https.go (L321-L328)
according to some bug reports (such like #404 and the resolve_preference
one report via telegram private message), some users use http proxy, got a
http 502 error without any useful logs.
This commit is contained in:
parent
7c9fbf22dd
commit
2fb70bdb58
@ -228,14 +228,19 @@ func client(config *clientConfig) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
proxy, err := hyHTTP.NewProxyHTTPServer(client, transport.DefaultClientTransport,
|
proxy, err := hyHTTP.NewProxyHTTPServer(client, transport.DefaultClientTransport,
|
||||||
time.Duration(config.HTTP.Timeout)*time.Second, aclEngine,
|
time.Duration(config.HTTP.Timeout)*time.Second, aclEngine, authFunc,
|
||||||
func(reqAddr string, action acl.Action, arg string) {
|
func(reqAddr string, action acl.Action, arg string) {
|
||||||
logrus.WithFields(logrus.Fields{
|
logrus.WithFields(logrus.Fields{
|
||||||
"action": actionToString(action, arg),
|
"action": actionToString(action, arg),
|
||||||
"dst": defaultIPMasker.Mask(reqAddr),
|
"dst": defaultIPMasker.Mask(reqAddr),
|
||||||
}).Debug("HTTP request")
|
}).Debug("HTTP request")
|
||||||
},
|
},
|
||||||
authFunc)
|
func(reqAddr string, err error) {
|
||||||
|
logrus.WithFields(logrus.Fields{
|
||||||
|
"error": err,
|
||||||
|
"dst": defaultIPMasker.Mask(reqAddr),
|
||||||
|
}).Info("HTTP error")
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithField("error", err).Fatal("Failed to initialize HTTP server")
|
logrus.WithField("error", err).Fatal("Failed to initialize HTTP server")
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func NewProxyHTTPServer(hyClient *core.Client, transport *transport.ClientTransport, idleTimeout time.Duration,
|
func NewProxyHTTPServer(hyClient *core.Client, transport *transport.ClientTransport, idleTimeout time.Duration,
|
||||||
aclEngine *acl.Engine, newDialFunc func(reqAddr string, action acl.Action, arg string),
|
aclEngine *acl.Engine,
|
||||||
basicAuthFunc func(user, password string) bool,
|
basicAuthFunc func(user, password string) bool,
|
||||||
|
newDialFunc func(reqAddr string, action acl.Action, arg string),
|
||||||
|
proxyErrorFunc func(reqAddr string, err error),
|
||||||
) (*goproxy.ProxyHttpServer, error) {
|
) (*goproxy.ProxyHttpServer, error) {
|
||||||
proxy := goproxy.NewProxyHttpServer()
|
proxy := goproxy.NewProxyHttpServer()
|
||||||
proxy.Logger = &nopLogger{}
|
proxy.Logger = &nopLogger{}
|
||||||
@ -46,27 +48,44 @@ func NewProxyHTTPServer(hyClient *core.Client, transport *transport.ClientTransp
|
|||||||
if resErr != nil {
|
if resErr != nil {
|
||||||
return nil, resErr
|
return nil, resErr
|
||||||
}
|
}
|
||||||
return transport.DialTCP(&net.TCPAddr{
|
conn, err := transport.DialTCP(&net.TCPAddr{
|
||||||
IP: ipAddr.IP,
|
IP: ipAddr.IP,
|
||||||
Port: int(port),
|
Port: int(port),
|
||||||
Zone: ipAddr.Zone,
|
Zone: ipAddr.Zone,
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
proxyErrorFunc(addr, err)
|
||||||
|
}
|
||||||
|
return conn, err
|
||||||
case acl.ActionProxy:
|
case acl.ActionProxy:
|
||||||
return hyClient.DialTCP(addr)
|
conn, err := hyClient.DialTCP(addr)
|
||||||
|
if err != nil {
|
||||||
|
proxyErrorFunc(addr, err)
|
||||||
|
}
|
||||||
|
return conn, err
|
||||||
case acl.ActionBlock:
|
case acl.ActionBlock:
|
||||||
return nil, errors.New("blocked by ACL")
|
err := errors.New("blocked by ACL")
|
||||||
|
proxyErrorFunc(addr, err)
|
||||||
|
return nil, err
|
||||||
case acl.ActionHijack:
|
case acl.ActionHijack:
|
||||||
hijackIPAddr, err := transport.ResolveIPAddr(arg)
|
hijackIPAddr, err := transport.ResolveIPAddr(arg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
proxyErrorFunc(addr, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return transport.DialTCP(&net.TCPAddr{
|
conn, err := transport.DialTCP(&net.TCPAddr{
|
||||||
IP: hijackIPAddr.IP,
|
IP: hijackIPAddr.IP,
|
||||||
Port: int(port),
|
Port: int(port),
|
||||||
Zone: hijackIPAddr.Zone,
|
Zone: hijackIPAddr.Zone,
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
proxyErrorFunc(addr, err)
|
||||||
|
}
|
||||||
|
return conn, err
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unknown action %d", action)
|
err := fmt.Errorf("unknown action %d", action)
|
||||||
|
proxyErrorFunc(addr, err)
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
IdleConnTimeout: idleTimeout,
|
IdleConnTimeout: idleTimeout,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user