| 79 | } |
| 80 | |
| 81 | func (w *bodyWriter) Write(b []byte) (int, error) { |
| 82 | // Capture into the trace buffer up to maxBytes, then drop the overflow |
| 83 | // so a chatty endpoint can't grow the buffer without bound. The full |
| 84 | // payload still flows through to the real client below. |
| 85 | w.totalBytes += len(b) |
| 86 | if w.maxBytes <= 0 { |
| 87 | w.body.Write(b) |
| 88 | } else if remain := w.maxBytes - w.body.Len(); remain > 0 { |
| 89 | if remain >= len(b) { |
| 90 | w.body.Write(b) |
| 91 | } else { |
| 92 | w.body.Write(b[:remain]) |
| 93 | w.truncated = true |
| 94 | } |
| 95 | } else { |
| 96 | w.truncated = true |
| 97 | } |
| 98 | return w.ResponseWriter.Write(b) |
| 99 | } |
| 100 | |
| 101 | func (w *bodyWriter) Flush() { |
| 102 | if flusher, ok := w.ResponseWriter.(http.Flusher); ok { |