diff options
| author | JP Appel <jeanpierre.appel01@gmail.com> | 2024-10-05 23:57:02 -0400 |
|---|---|---|
| committer | JP Appel <jeanpierre.appel01@gmail.com> | 2024-10-05 23:57:02 -0400 |
| commit | ad4befb67ef768f96f481d0917e459e49a32308f (patch) | |
| tree | c0c1bb985432971034c3015eaa93ddc68cc670c5 | |
| parent | 19102f46526a768b88f6312cdae05de50ea90535 (diff) | |
Fix writting docker logs to http response
Now properly strips binary data from response
| -rw-r--r-- | api/api.go | 11 |
1 files changed, 8 insertions, 3 deletions
@@ -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) { |
