| 63 | } |
| 64 | |
| 65 | func (w *StatusWriter) Write(b []byte) (int, error) { |
| 66 | const maxBodySize = 4096 |
| 67 | |
| 68 | if !w.wroteHeader { |
| 69 | w.Status = http.StatusOK |
| 70 | w.wroteHeader = true |
| 71 | } |
| 72 | |
| 73 | if w.Status >= http.StatusBadRequest { |
| 74 | // This is technically wrong as multiple calls to write |
| 75 | // will simply overwrite w.ResponseBody but given that |
| 76 | // we typically only write to the response body once |
| 77 | // and this field is only used for logging I'm leaving |
| 78 | // this as-is. |
| 79 | w.responseBody = make([]byte, minInt(len(b), maxBodySize)) |
| 80 | copy(w.responseBody, b) |
| 81 | } |
| 82 | |
| 83 | return w.ResponseWriter.Write(b) |
| 84 | } |
| 85 | |
| 86 | func minInt(a, b int) int { |
| 87 | if a < b { |