Browse code

Update gorilla/context

Race condition was fixed recently
Docker-DCO-1.1-Signed-off-by: Alexandr Morozov <lk4d4math@gmail.com> (github: LK4D4)

LK4D4 authored on 2014/06/28 17:38:29
Showing 2 changed files
... ...
@@ -41,7 +41,7 @@ clone() {
41 41
 
42 42
 clone git github.com/kr/pty 67e2db24c8
43 43
 
44
-clone git github.com/gorilla/context b06ed15e1c
44
+clone git github.com/gorilla/context 14f550f51a
45 45
 
46 46
 clone git github.com/gorilla/mux 136d54f81f
47 47
 
... ...
@@ -30,9 +30,10 @@ func Set(r *http.Request, key, val interface{}) {
30 30
 // Get returns a value stored for a given key in a given request.
31 31
 func Get(r *http.Request, key interface{}) interface{} {
32 32
 	mutex.RLock()
33
-	if data[r] != nil {
33
+	if ctx := data[r]; ctx != nil {
34
+		value := ctx[key]
34 35
 		mutex.RUnlock()
35
-		return data[r][key]
36
+		return value
36 37
 	}
37 38
 	mutex.RUnlock()
38 39
 	return nil
... ...
@@ -54,20 +55,28 @@ func GetOk(r *http.Request, key interface{}) (interface{}, bool) {
54 54
 func GetAll(r *http.Request) map[interface{}]interface{} {
55 55
 	mutex.RLock()
56 56
 	if context, ok := data[r]; ok {
57
+		result := make(map[interface{}]interface{}, len(context))
58
+		for k, v := range context {
59
+			result[k] = v
60
+		}
57 61
 		mutex.RUnlock()
58
-		return context
62
+		return result
59 63
 	}
60 64
 	mutex.RUnlock()
61 65
 	return nil
62 66
 }
63 67
 
64
-// GetAllOk returns all stored values for the request as a map. It returns not
65
-// ok if the request was never registered.
68
+// GetAllOk returns all stored values for the request as a map and a boolean value that indicates if
69
+// the request was registered.
66 70
 func GetAllOk(r *http.Request) (map[interface{}]interface{}, bool) {
67 71
 	mutex.RLock()
68 72
 	context, ok := data[r]
73
+	result := make(map[interface{}]interface{}, len(context))
74
+	for k, v := range context {
75
+		result[k] = v
76
+	}
69 77
 	mutex.RUnlock()
70
-	return context, ok
78
+	return result, ok
71 79
 }
72 80
 
73 81
 // Delete removes a value stored for a given key in a given request.