mirror of
https://github.com/bluenviron/mediamtx
synced 2025-01-08 07:50:02 +00:00
36 lines
731 B
Go
36 lines
731 B
Go
package core
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type httpLogWriter struct {
|
|
gin.ResponseWriter
|
|
buf bytes.Buffer
|
|
}
|
|
|
|
func (w *httpLogWriter) Write(b []byte) (int, error) {
|
|
w.buf.Write(b)
|
|
return w.ResponseWriter.Write(b)
|
|
}
|
|
|
|
func (w *httpLogWriter) WriteString(s string) (int, error) {
|
|
w.buf.WriteString(s)
|
|
return w.ResponseWriter.WriteString(s)
|
|
}
|
|
|
|
func (w *httpLogWriter) dump() string {
|
|
var buf bytes.Buffer
|
|
fmt.Fprintf(&buf, "%s %d %s\n", "HTTP/1.1", w.ResponseWriter.Status(), http.StatusText(w.ResponseWriter.Status()))
|
|
w.ResponseWriter.Header().Write(&buf)
|
|
buf.Write([]byte("\n"))
|
|
if w.buf.Len() > 0 {
|
|
fmt.Fprintf(&buf, "(body of %d bytes)", w.buf.Len())
|
|
}
|
|
return buf.String()
|
|
}
|