diff --git a/internal/web/logs.go b/internal/web/logs.go index 00b35313..eee34b67 100644 --- a/internal/web/logs.go +++ b/internal/web/logs.go @@ -3,6 +3,7 @@ package web import ( "compress/gzip" "context" + "strings" "github.com/goccy/go-json" @@ -30,12 +31,22 @@ func (h *handler) downloadLogs(w http.ResponseWriter, r *http.Request) { } now := time.Now() + nowFmt := now.Format("2006-01-02T15-04-05") + + contentDisposition := fmt.Sprintf("attachment; filename=%s-%s.log", container.Name, nowFmt) + + if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") { + w.Header().Set("Content-Disposition", contentDisposition) + w.Header().Set("Content-Encoding", "gzip") + w.Header().Set("Content-Type", "application/text") + } else { + w.Header().Set("Content-Disposition", contentDisposition+".gz") + w.Header().Set("Content-Type", "application/gzip") + } - w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%s-%s.log.gz", container.Name, now.Format("2006-01-02T15-04-05"))) - w.Header().Set("Content-Type", "application/gzip") zw := gzip.NewWriter(w) defer zw.Close() - zw.Name = fmt.Sprintf("%s-%s.log", container.Name, now.Format("2006-01-02T15-04-05")) + zw.Name = fmt.Sprintf("%s-%s.log", container.Name, nowFmt) zw.Comment = "Logs generated by Dozzle" zw.ModTime = now