This commit is contained in:
Gerasimos Maropoulos
2016-07-12 08:40:24 +02:00
committed by Aliaksandr Valialkin
parent 141ac46e4c
commit 006fac3cba
2 changed files with 22 additions and 0 deletions
+11
View File
@@ -481,6 +481,17 @@ func (ctx *RequestCtx) UserValueBytes(key []byte) interface{} {
return ctx.userValues.GetBytes(key)
}
// VisitUserValues calls visitor for each existing userValue.
//
// visitor must not retain references to key and value after returning.
// Make key and/or value copies if you need storing them after returning.
func (ctx *RequestCtx) VisitUserValues(visitor func([]byte, interface{})) {
for i, n := 0, len(ctx.userValues); i < n; i++ {
kv := &ctx.userValues[i]
visitor(kv.key, kv.value)
}
}
// IsTLS returns true if the underlying connection is tls.Conn.
//
// tls.Conn is an encrypted connection (aka SSL, HTTPS).
+11
View File
@@ -1031,6 +1031,17 @@ func TestRequestCtxUserValue(t *testing.T) {
t.Fatalf("unexpected value obtained for key %q: %v. Expecting %d", k, v, i)
}
}
vlen := 0
ctx.VisitUserValues(func(key []byte, value interface{}) {
vlen++
v := ctx.UserValueBytes(key)
if v != value {
t.Fatalf("unexpected value obtained from VisitUserValues for key: %q, expecting: %#v but got: %#v", key, v, value)
}
})
if len(ctx.userValues) != vlen {
t.Fatalf("the length of user values returned from VisitUserValues is not equal to the length of the userValues, expecting: %d but got: %d", len(ctx.userValues), vlen)
}
}
func TestServerHeadRequest(t *testing.T) {