writer.go 715 B

123456789101112131415161718192021222324252627282930313233343536
  1. package logger
  2. import (
  3. "bufio"
  4. "errors"
  5. "net"
  6. "net/http"
  7. )
  8. type ResponseWriter struct {
  9. http.ResponseWriter
  10. Content []byte
  11. Size int
  12. Status int
  13. }
  14. func (w *ResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
  15. if h, ok := w.ResponseWriter.(http.Hijacker); ok {
  16. return h.Hijack()
  17. }
  18. return nil, nil, errors.New("hijack not supported")
  19. }
  20. func (w *ResponseWriter) Write(b []byte) (int, error) {
  21. if RollBarEnabled && !RollBarSkipStatusCodes.contain(w.Status) {
  22. w.Content = append(w.Content, b...)
  23. }
  24. size, err := w.ResponseWriter.Write(b)
  25. w.Size += size
  26. return size, err
  27. }
  28. func (w *ResponseWriter) WriteHeader(status int) {
  29. w.Status = status
  30. w.ResponseWriter.WriteHeader(status)
  31. }