fix: proxyHandler — io.Copy вместо ручного цикла
This commit is contained in:
+5
-23
@@ -327,30 +327,12 @@ func proxyHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.Header().Set("Content-Type", "application/octet-stream")
|
w.Header().Set("Content-Type", "application/octet-stream")
|
||||||
w.Header().Set("Last-Modified", stat.LastModified.Format(http.TimeFormat))
|
w.Header().Set("Last-Modified", stat.LastModified.Format(http.TimeFormat))
|
||||||
|
|
||||||
buf := make([]byte, 64*1024) // 64KB buffer
|
written, err := io.Copy(w, obj)
|
||||||
flusher, canFlush := w.(http.Flusher)
|
if err != nil {
|
||||||
written := int64(0)
|
log.Printf("Error streaming object: %v (sent %d/%d bytes)", err, written, stat.Size)
|
||||||
for {
|
} else {
|
||||||
n, readErr := obj.Read(buf)
|
log.Printf("Proxy: sent %d bytes for %s", written, key)
|
||||||
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) {
|
func discoveryHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
Reference in New Issue
Block a user