mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-13 15:46:49 +03:00
Call Close on user values stored via RequestCtx.SetUserValue if these values implement io.Closer
This commit is contained in:
+12
@@ -1,5 +1,9 @@
|
||||
package fasthttp
|
||||
|
||||
import (
|
||||
"io"
|
||||
)
|
||||
|
||||
type userDataKV struct {
|
||||
key []byte
|
||||
value interface{}
|
||||
@@ -55,5 +59,13 @@ func (d *userData) GetBytes(key []byte) interface{} {
|
||||
}
|
||||
|
||||
func (d *userData) Reset() {
|
||||
args := *d
|
||||
n := len(args)
|
||||
for i := 0; i < n; i++ {
|
||||
v := args[i].value
|
||||
if vc, ok := v.(io.Closer); ok {
|
||||
vc.Close()
|
||||
}
|
||||
}
|
||||
*d = (*d)[:0]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user