diff options
author | feistel <6742251-feistel@users.noreply.gitlab.com> | 2022-01-29 19:52:48 +0300 |
---|---|---|
committer | feistel <6742251-feistel@users.noreply.gitlab.com> | 2022-01-29 19:52:48 +0300 |
commit | 4f047b8fdfa87cc80b7f5d33c03c97206d855765 (patch) | |
tree | 44f0eed70b0396c439e8c4cb5b580cdbf0cdbb4b /internal | |
parent | 008e2afc8d6de32a30696dbf813ebc0fdf5192c7 (diff) |
fix: catch io.copy errors when serving content
Diffstat (limited to 'internal')
-rw-r--r-- | internal/vfs/serving/serving.go | 10 |
1 files changed, 8 insertions, 2 deletions
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) + } } } |