Files
Authentication/models/http.go
T
2025-11-25 15:12:31 +08:00

27 lines
610 B
Go

package models
import "net/http"
// FlusherPreservingResponseWriter wraps http.ResponseWriter and preserves http.Flusher for SSE endpoints.
type FlusherPreservingResponseWriter struct {
http.ResponseWriter
}
func (w *FlusherPreservingResponseWriter) Flush() {
if f, ok := w.ResponseWriter.(http.Flusher); ok {
f.Flush()
}
}
// ResponseWriter wraps http.ResponseWriter to track response size for metrics
type ResponseWriter struct {
http.ResponseWriter
Size int
}
func (rw *ResponseWriter) Write(b []byte) (int, error) {
size, err := rw.ResponseWriter.Write(b)
rw.Size += size
return size, err
}