Permalink
Browse files

Lock with token and global mutex

  • Loading branch information...
rosylilly committed Oct 31, 2015
1 parent f910cfc commit af22acf395d6a69a8b5d45208195090ec9b7371f
Showing with 18 additions and 1 deletion.
  1. +18 −1 5f/webapp/golang/proxy.go
View
@@ -93,12 +93,29 @@ func main() {
http.ListenAndServe(":9293", nil)
}
+var tokensMutex = new(sync.Mutex)
+var tokenLocks = map[string]*sync.Mutex{}
+
func getResponse(req *http.Request) (*http.Request, *http.Response) {
endpoint := ENDPOINTS[req.URL.Path]
req.URL.Host = endpoint
req.URL.Scheme = "https"
+
+ token := req.Header.Get("X-Perfect-Security-Token")
+
+ tokensMutex.Lock()
+ mx, ok := tokenLocks[token]
+ if !ok {
+ mx = new(sync.Mutex)
+ tokenLocks[token] = mx
+ }
+ tokensMutex.Unlock()
+
+ mx.Lock()
+ defer mx.Unlock()
+
log.Printf("Request: %s", req.URL.String())
- log.Printf("Security Token: %s", req.Header.Get("X-Perfect-Security-Token"))
+ log.Printf("Security Token: %s", token)
nreq, err := http.NewRequest("GET", req.URL.String(), nil)
if err != nil {

0 comments on commit af22acf

Please sign in to comment.