Call Close on user values stored via RequestCtx.SetUserValue if these values implement io.Closer

This commit is contained in:
Aliaksandr Valialkin
2016-02-05 12:50:58 +02:00
parent df213349e2
commit eafcb74ce5
3 changed files with 48 additions and 1 deletions
+12
View File
@@ -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]
}