فهرست منبع

Update gorilla/context

Race condition was fixed recently
Docker-DCO-1.1-Signed-off-by: Alexandr Morozov <lk4d4math@gmail.com> (github: LK4D4)
LK4D4 11 سال پیش
والد
کامیت
ea464ea212
2فایلهای تغییر یافته به همراه16 افزوده شده و 7 حذف شده
  1. 1 1
      hack/vendor.sh
  2. 15 6
      vendor/src/github.com/gorilla/context/context.go

+ 1 - 1
hack/vendor.sh

@@ -41,7 +41,7 @@ clone() {
 
 clone git github.com/kr/pty 67e2db24c8
 
-clone git github.com/gorilla/context b06ed15e1c
+clone git github.com/gorilla/context 14f550f51a
 
 clone git github.com/gorilla/mux 136d54f81f
 

+ 15 - 6
vendor/src/github.com/gorilla/context/context.go

@@ -30,9 +30,10 @@ func Set(r *http.Request, key, val interface{}) {
 // Get returns a value stored for a given key in a given request.
 func Get(r *http.Request, key interface{}) interface{} {
 	mutex.RLock()
-	if data[r] != nil {
+	if ctx := data[r]; ctx != nil {
+		value := ctx[key]
 		mutex.RUnlock()
-		return data[r][key]
+		return value
 	}
 	mutex.RUnlock()
 	return nil
@@ -54,20 +55,28 @@ func GetOk(r *http.Request, key interface{}) (interface{}, bool) {
 func GetAll(r *http.Request) map[interface{}]interface{} {
 	mutex.RLock()
 	if context, ok := data[r]; ok {
+		result := make(map[interface{}]interface{}, len(context))
+		for k, v := range context {
+			result[k] = v
+		}
 		mutex.RUnlock()
-		return context
+		return result
 	}
 	mutex.RUnlock()
 	return nil
 }
 
-// GetAllOk returns all stored values for the request as a map. It returns not
-// ok if the request was never registered.
+// GetAllOk returns all stored values for the request as a map and a boolean value that indicates if
+// the request was registered.
 func GetAllOk(r *http.Request) (map[interface{}]interface{}, bool) {
 	mutex.RLock()
 	context, ok := data[r]
+	result := make(map[interface{}]interface{}, len(context))
+	for k, v := range context {
+		result[k] = v
+	}
 	mutex.RUnlock()
-	return context, ok
+	return result, ok
 }
 
 // Delete removes a value stored for a given key in a given request.