-
Notifications
You must be signed in to change notification settings - Fork 57
/
error.go
59 lines (53 loc) · 1.52 KB
/
error.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package httpproxy
import (
"io"
"net"
"os"
"syscall"
)
// Library specific errors.
var (
ErrPanic = NewError("panic")
ErrResponseWrite = NewError("response write")
ErrRequestRead = NewError("request read")
ErrRemoteConnect = NewError("remote connect")
ErrNotSupportHijacking = NewError("hijacking not supported")
ErrTLSSignHost = NewError("TLS sign host")
ErrTLSHandshake = NewError("TLS handshake")
ErrAbsURLAfterCONNECT = NewError("absolute URL after CONNECT")
ErrRoundTrip = NewError("round trip")
ErrUnsupportedTransferEncoding = NewError("unsupported transfer encoding")
ErrNotSupportHTTPVer = NewError("http version not supported")
)
// Error struct is base of library specific errors.
type Error struct {
ErrString string
}
// NewError returns a new Error.
func NewError(errString string) *Error {
return &Error{errString}
}
// Error implements error interface.
func (e *Error) Error() string {
return e.ErrString
}
func isConnectionClosed(err error) bool {
if err == nil {
return false
}
if err == io.EOF {
return true
}
i := 0
var newerr = &err
for opError, ok := (*newerr).(*net.OpError); ok && i < 10; {
i++
newerr = &opError.Err
if syscallError, ok := (*newerr).(*os.SyscallError); ok {
if syscallError.Err == syscall.EPIPE || syscallError.Err == syscall.ECONNRESET || syscallError.Err == syscall.EPROTOTYPE {
return true
}
}
}
return false
}