From be5fe36d6397ac5e633599a3be6a53295871d2f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNaeel=E2=80=9D?= Date: Sun, 9 Aug 2026 10:00:16 +0400 Subject: [PATCH] =?UTF-8?q?fix:=20proxyHandler=20=E2=80=94=20streaming=20?= =?UTF-8?q?=D1=81=20Flush,=2064KB=20=D0=B1=D1=83=D1=84=D0=B5=D1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/main.go | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/server/main.go b/server/main.go index a963fdd..7aa02c7 100644 --- a/server/main.go +++ b/server/main.go @@ -320,9 +320,30 @@ func proxyHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/octet-stream") w.Header().Set("Last-Modified", stat.LastModified.Format(http.TimeFormat)) - if _, err := io.Copy(w, obj); err != nil { - log.Printf("Error streaming object: %v", err) + buf := make([]byte, 64*1024) // 64KB buffer + flusher, canFlush := w.(http.Flusher) + written := int64(0) + for { + n, readErr := obj.Read(buf) + if n > 0 { + nw, writeErr := w.Write(buf[:n]) + if writeErr != nil { + log.Printf("Error writing response: %v", writeErr) + return + } + written += int64(nw) + if canFlush { + flusher.Flush() + } + } + if readErr != nil { + if readErr != io.EOF { + log.Printf("Error reading object: %v", readErr) + } + break + } } + log.Printf("Proxy: sent %d/%d bytes for %s", written, stat.Size, key) } func discoveryHandler(w http.ResponseWriter, r *http.Request) {