Fix webui streaming recovery regressions
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
package webui
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"html"
|
||||
"io"
|
||||
"log/slog"
|
||||
"math"
|
||||
"mime"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -373,6 +376,38 @@ func (w *trackingResponseWriter) Write(p []byte) (int, error) {
|
||||
return w.ResponseWriter.Write(p)
|
||||
}
|
||||
|
||||
func (w *trackingResponseWriter) Flush() {
|
||||
w.wroteHeader = true
|
||||
if f, ok := w.ResponseWriter.(http.Flusher); ok {
|
||||
f.Flush()
|
||||
}
|
||||
}
|
||||
|
||||
func (w *trackingResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
||||
h, ok := w.ResponseWriter.(http.Hijacker)
|
||||
if !ok {
|
||||
return nil, nil, fmt.Errorf("hijacking not supported")
|
||||
}
|
||||
return h.Hijack()
|
||||
}
|
||||
|
||||
func (w *trackingResponseWriter) Push(target string, opts *http.PushOptions) error {
|
||||
p, ok := w.ResponseWriter.(http.Pusher)
|
||||
if !ok {
|
||||
return http.ErrNotSupported
|
||||
}
|
||||
return p.Push(target, opts)
|
||||
}
|
||||
|
||||
func (w *trackingResponseWriter) ReadFrom(r io.Reader) (int64, error) {
|
||||
rf, ok := w.ResponseWriter.(io.ReaderFrom)
|
||||
if !ok {
|
||||
return io.Copy(w.ResponseWriter, r)
|
||||
}
|
||||
w.wroteHeader = true
|
||||
return rf.ReadFrom(r)
|
||||
}
|
||||
|
||||
func recoverMiddleware(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
tw := &trackingResponseWriter{ResponseWriter: w}
|
||||
|
||||
Reference in New Issue
Block a user