in go/wtl/proxy/driverhub/debugger/debugger.go [107:176]
func (d *Debugger) Request(r *http.Request) {
// Capture request body
body, err := capture(r.Body)
if err != nil {
log.Fatalf("Error reading request body: %v", err)
}
r.Body = body
resp := &response{
Request: &request{
Method: r.Method,
Path: r.URL.Path,
Body: body.captured,
},
}
// Identify if we should be continuing or waiting
d.mu.RLock()
step := d.step
if !step {
for _, bp := range d.breakpoints {
if bp.matches(resp.Request) {
step = true
break
}
}
}
d.mu.RUnlock()
if step {
resp.Status = "waiting"
} else {
resp.Status = "running"
}
// Send request info to client client
bytes, err := json.Marshal(resp)
if err != nil {
log.Print(err)
return
}
if _, err := d.conn.Write(bytes); err != nil {
log.Print(err)
}
if _, err := d.conn.Write([]byte("\n")); err != nil {
log.Print(err)
}
// Not stepping, so return.
if !step {
return
}
// Wait for step/continue command from front end.
// TODO(DrMarcII): Race condition here, but it is racing a human, so not too worried about it.
waiting := make(chan interface{})
d.mu.Lock()
d.waiting = waiting
d.mu.Unlock()
<-waiting
d.mu.Lock()
d.waiting = nil
d.mu.Unlock()
}