package proxy import ( "log" "net/http" "strings" ) // Dump logs the request and response bodies of requests whose path contains Match (T5DE_PROXY_DUMP, for finding // out what IMVU's APIs send). It may log personal data: only for test accounts. type Dump struct { Match string Log *log.Logger } func (d Dump) Intercept(x *Exchange) error { if d.Match == "" || !strings.Contains(x.URL.Path, d.Match) { return nil } d.Log.Printf("dump: %s %s\n%s", x.Request.Method, x.URL, x.Body) next := x.ModifyResponse x.ModifyResponse = func(resp *http.Response, body []byte) ([]byte, error) { if next != nil { var err error if body, err = next(resp, body); err != nil { return nil, err } } d.Log.Printf("dump: %s answered %d\n%s", x.URL.Path, resp.StatusCode, body) return body, nil } return nil }