send json response bodies to tracerx

This commit is contained in:
risk danger olson 2015-11-18 10:51:06 -07:00
parent 88d1f7af56
commit 8bb4d4f160

@ -210,11 +210,21 @@ func isTraceableContent(h http.Header) bool {
} }
func countingRequest(req *http.Request) *countingReadCloser { func countingRequest(req *http.Request) *countingReadCloser {
return &countingReadCloser{request: req, ReadCloser: req.Body, isTraceableType: isTraceableContent(req.Header)} return &countingReadCloser{
request: req,
ReadCloser: req.Body,
isTraceableType: isTraceableContent(req.Header),
useGitTrace: false,
}
} }
func countingResponse(res *http.Response) *countingReadCloser { func countingResponse(res *http.Response) *countingReadCloser {
return &countingReadCloser{response: res, ReadCloser: res.Body, isTraceableType: isTraceableContent(res.Header)} return &countingReadCloser{
response: res,
ReadCloser: res.Body,
isTraceableType: isTraceableContent(res.Header),
useGitTrace: true,
}
} }
type countingReadCloser struct { type countingReadCloser struct {
@ -222,6 +232,7 @@ type countingReadCloser struct {
request *http.Request request *http.Request
response *http.Response response *http.Response
isTraceableType bool isTraceableType bool
useGitTrace bool
io.ReadCloser io.ReadCloser
} }
@ -233,8 +244,15 @@ func (c *countingReadCloser) Read(b []byte) (int, error) {
c.Count += n c.Count += n
if Config.isTracingHttp && c.isTraceableType { if c.isTraceableType {
fmt.Fprint(os.Stderr, string(b[0:n])) chunk := string(b[0:n])
if c.useGitTrace {
tracerx.Printf("HTTP: %s", chunk)
}
if Config.isTracingHttp {
fmt.Fprint(os.Stderr, chunk)
}
} }
if err == io.EOF && Config.isLoggingStats { if err == io.EOF && Config.isLoggingStats {