From ad4befb67ef768f96f481d0917e459e49a32308f Mon Sep 17 00:00:00 2001 From: JP Appel Date: Sat, 5 Oct 2024 23:57:02 -0400 Subject: Fix writting docker logs to http response Now properly strips binary data from response --- api/api.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'api') diff --git a/api/api.go b/api/api.go index 957651e..b909755 100644 --- a/api/api.go +++ b/api/api.go @@ -3,12 +3,13 @@ package api import ( "context" "encoding/json" - "io" "log/slog" "net/http" "os" "strconv" "time" + + "github.com/docker/docker/pkg/stdcopy" ) type ServerStatus struct { @@ -68,7 +69,7 @@ func VttLogs(w http.ResponseWriter, req *http.Request) { linesParam := req.URL.Query().Get("lines") if linesParam != "" { - lines_64, err := strconv.ParseUint(linesParam, 10, 64) + lines_64, err := strconv.ParseUint(linesParam, 10, 0) if err != nil { Logger.ErrorContext(req.Context(), "Invalid line count in vtt logs request", slog.Any("err", err)) http.Error(w, "Invalid line count in request", http.StatusBadRequest) @@ -85,7 +86,11 @@ func VttLogs(w http.ResponseWriter, req *http.Request) { } defer logReader.Close() - io.Copy(w, logReader) + if _, err = stdcopy.StdCopy(w, w, logReader); err != nil { + Logger.Error("Error occured while writting logs to response", slog.Any("err", err), slog.Any("request", req)) + http.Error(w, "Error occured while writting logs", http.StatusInternalServerError) + return + } } func SiteOnline(w http.ResponseWriter, req *http.Request) { -- cgit v1.2.3