From 4f047b8fdfa87cc80b7f5d33c03c97206d855765 Mon Sep 17 00:00:00 2001 From: feistel <6742251-feistel@users.noreply.gitlab.com> Date: Sat, 29 Jan 2022 17:52:48 +0100 Subject: fix: catch io.copy errors when serving content --- internal/vfs/serving/serving.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'internal') diff --git a/internal/vfs/serving/serving.go b/internal/vfs/serving/serving.go index 6f45e1d5..8f86d476 100644 --- a/internal/vfs/serving/serving.go +++ b/internal/vfs/serving/serving.go @@ -47,10 +47,16 @@ func serveContent(w http.ResponseWriter, r *http.Request, modtime time.Time, con return } - w.WriteHeader(code) + if r.Method == http.MethodHead { + w.WriteHeader(code) + } if r.Method != http.MethodHead { - io.Copy(w, content) + if _, err := io.Copy(w, content); err != nil { + errortracking.Capture(err, errortracking.WithRequest(r), errortracking.WithStackTrace()) + logging.LogRequest(r).WithError(err).Error("error serving content") + httperrors.Serve500(w) + } } } -- cgit v1.2.3