mirror of
https://github.com/kataras/iris.git
synced 2025-03-21 11:16:28 +01:00
Context.IsCanceled() minor improvement
This commit is contained in:
parent
2a048df5c7
commit
25ad31be50
|
@ -506,6 +506,10 @@ var (
|
||||||
//
|
//
|
||||||
// A shortcut for the `context#IsErrPath`.
|
// A shortcut for the `context#IsErrPath`.
|
||||||
IsErrPath = context.IsErrPath
|
IsErrPath = context.IsErrPath
|
||||||
|
// IsErrCanceled reports whether the "err" is caused by a cancellation or timeout.
|
||||||
|
//
|
||||||
|
// A shortcut for the `context#IsErrCanceled`.
|
||||||
|
IsErrCanceled = context.IsErrCanceled
|
||||||
// ErrEmptyForm is the type error which API users can make use of
|
// ErrEmptyForm is the type error which API users can make use of
|
||||||
// to check if a form was empty on `Context.ReadForm`.
|
// to check if a form was empty on `Context.ReadForm`.
|
||||||
//
|
//
|
||||||
|
|
|
@ -232,14 +232,28 @@ func (ctx *Context) EndRequest() {
|
||||||
// Note that it will always return true
|
// Note that it will always return true
|
||||||
// when called from a goroutine after the request-response lifecycle.
|
// when called from a goroutine after the request-response lifecycle.
|
||||||
func (ctx *Context) IsCanceled() bool {
|
func (ctx *Context) IsCanceled() bool {
|
||||||
|
var err error
|
||||||
if reqCtx := ctx.request.Context(); reqCtx != nil {
|
if reqCtx := ctx.request.Context(); reqCtx != nil {
|
||||||
err := reqCtx.Err()
|
err = reqCtx.Err()
|
||||||
if err != nil && errors.Is(err, stdContext.Canceled) {
|
} else {
|
||||||
return true
|
err = ctx.GetErr()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return IsErrCanceled(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsErrCanceled reports whether the "err" is caused by a cancellation or timeout.
|
||||||
|
func IsErrCanceled(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
var netErr net.Error
|
||||||
|
return (errors.As(err, &netErr) && netErr.Timeout()) ||
|
||||||
|
errors.Is(err, stdContext.Canceled) ||
|
||||||
|
errors.Is(err, stdContext.DeadlineExceeded) ||
|
||||||
|
errors.Is(err, http.ErrHandlerTimeout) ||
|
||||||
|
err.Error() == "closed pool"
|
||||||
}
|
}
|
||||||
|
|
||||||
// OnConnectionClose registers the "cb" Handler
|
// OnConnectionClose registers the "cb" Handler
|
||||||
|
@ -1483,6 +1497,7 @@ func (ctx *Context) URLParamSlice(name string) []string {
|
||||||
if v == "" {
|
if v == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
normalizedValues = append(normalizedValues, v)
|
normalizedValues = append(normalizedValues, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user