Suppress expected error

This commit is contained in:
世界 2022-08-25 10:56:57 +08:00
parent 350729cde8
commit a940703ae1
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
3 changed files with 18 additions and 2 deletions

View file

@ -603,5 +603,8 @@ func wrapHttpError(err error) error {
if strings.Contains(err.Error(), "body closed by handler") {
return net.ErrClosed
}
if strings.Contains(err.Error(), "canceled with error code 268") {
return io.EOF
}
return err
}

View file

@ -102,5 +102,8 @@ func wrapError(err error) error {
if strings.Contains(err.Error(), "EOF") {
return io.EOF
}
if strings.Contains(err.Error(), "the client connection is closing") {
return net.ErrClosed
}
return err
}

View file

@ -8,6 +8,7 @@ import (
"time"
"github.com/sagernet/sing/common"
E "github.com/sagernet/sing/common/exceptions"
)
type HTTPConn struct {
@ -16,11 +17,13 @@ type HTTPConn struct {
}
func (c *HTTPConn) Read(b []byte) (n int, err error) {
return c.reader.Read(b)
n, err = c.reader.Read(b)
return n, wrapError(err)
}
func (c *HTTPConn) Write(b []byte) (n int, err error) {
return c.writer.Write(b)
n, err = c.writer.Write(b)
return n, wrapError(err)
}
func (c *HTTPConn) Close() error {
@ -59,3 +62,10 @@ func (c *ServerHTTPConn) Write(b []byte) (n int, err error) {
}
return
}
func wrapError(err error) error {
if E.IsMulti(err, io.ErrUnexpectedEOF) {
return io.EOF
}
return err
}