diff options
author | Jaime Martinez <jmartinez@gitlab.com> | 2022-01-31 02:16:25 +0300 |
---|---|---|
committer | Jaime Martinez <jmartinez@gitlab.com> | 2022-01-31 02:16:25 +0300 |
commit | 682a80ca535e01d6c6e22540b9f15afe5f774016 (patch) | |
tree | f62aa330835bc20e6474d0505efa49ec8aef9255 /internal | |
parent | 41802815aa64a38e0db8957e43857a3b75f1517f (diff) | |
parent | 60f5b3459ee09c1439f1ee31938e6ee4b88f5ec5 (diff) |
Merge branch 'fix/catch-serve-errors' into 'master'
fix: catch io.copy errors when serving content
See merge request gitlab-org/gitlab-pages!676
Diffstat (limited to 'internal')
-rw-r--r-- | internal/vfs/serving/serving.go | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/internal/vfs/serving/serving.go b/internal/vfs/serving/serving.go index 6f45e1d5..57b0228f 100644 --- a/internal/vfs/serving/serving.go +++ b/internal/vfs/serving/serving.go @@ -47,10 +47,17 @@ func serveContent(w http.ResponseWriter, r *http.Request, modtime time.Time, con return } - w.WriteHeader(code) + if r.Method == http.MethodHead { + w.WriteHeader(code) + return + } 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) + } } } |