File tree Expand file tree Collapse file tree 2 files changed +7
-0
lines changed Expand file tree Collapse file tree 2 files changed +7
-0
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,9 @@ const (
39
39
// BodyBytesKey indicates a default body bytes key.
40
40
const BodyBytesKey = "_gin-gonic/gin/bodybyteskey"
41
41
42
+ // ContextKey is the key that a Context returns itself for.
43
+ const ContextKey = "_gin-gonic/gin/contextkey"
44
+
42
45
// abortIndex represents a typical value used in abort functions.
43
46
const abortIndex int8 = math .MaxInt8 >> 1
44
47
@@ -1163,6 +1166,9 @@ func (c *Context) Value(key any) any {
1163
1166
if key == 0 {
1164
1167
return c .Request
1165
1168
}
1169
+ if key == ContextKey {
1170
+ return c
1171
+ }
1166
1172
if keyAsString , ok := key .(string ); ok {
1167
1173
if val , exists := c .Get (keyAsString ); exists {
1168
1174
return val
Original file line number Diff line number Diff line change @@ -1880,6 +1880,7 @@ func TestContextGolangContext(t *testing.T) {
1880
1880
assert .Equal (t , ti , time.Time {})
1881
1881
assert .False (t , ok )
1882
1882
assert .Equal (t , c .Value (0 ), c .Request )
1883
+ assert .Equal (t , c .Value (ContextKey ), c )
1883
1884
assert .Nil (t , c .Value ("foo" ))
1884
1885
1885
1886
c .Set ("foo" , "bar" )
You can’t perform that action at this time.
0 commit comments