diff --git a/dump.go b/dump.go index ec5401e..41ad8ff 100644 --- a/dump.go +++ b/dump.go @@ -1,11 +1,18 @@ package slogecho import ( + "bufio" "bytes" + "errors" "io" + "net" "net/http" ) +var _ http.ResponseWriter = (*bodyWriter)(nil) +var _ http.Flusher = (*bodyWriter)(nil) +var _ http.Hijacker = (*bodyWriter)(nil) + type bodyWriter struct { http.ResponseWriter body *bytes.Buffer @@ -13,7 +20,7 @@ type bodyWriter struct { bytes int } -// implements gin.ResponseWriter +// implements http.ResponseWriter func (w bodyWriter) Write(b []byte) (int, error) { if w.body != nil { if w.body.Len()+len(b) > w.maxSize { @@ -26,6 +33,22 @@ func (w bodyWriter) Write(b []byte) (int, error) { return w.ResponseWriter.Write(b) } +// implements http.Flusher +func (w bodyWriter) Flush() { + if w.ResponseWriter.(http.Flusher) != nil { + w.ResponseWriter.(http.Flusher).Flush() + } +} + +// implements http.Hijacker +func (w bodyWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { + if w.ResponseWriter.(http.Hijacker) != nil { + return w.ResponseWriter.(http.Hijacker).Hijack() + } + + return nil, nil, errors.New("Hijack not supported") +} + func newBodyWriter(writer http.ResponseWriter, maxSize int, recordBody bool) *bodyWriter { var body *bytes.Buffer if recordBody {