From 426502c7a091dd6d5803552cf83e172dec4fa255 Mon Sep 17 00:00:00 2001 From: Mmx Date: Sun, 1 Sep 2024 18:17:52 +0800 Subject: [PATCH 1/2] chore(webdav): fix warnings in HttpServe --- internal/net/serve.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/net/serve.go b/internal/net/serve.go index e58d7eb9f46..a93c7994712 100644 --- a/internal/net/serve.go +++ b/internal/net/serve.go @@ -87,9 +87,9 @@ func ServeHTTP(w http.ResponseWriter, r *http.Request, name string, modTime time sendSize := size var sendContent io.ReadCloser ranges, err := http_range.ParseRange(rangeReq, size) - switch err { - case nil: - case http_range.ErrNoOverlap: + switch { + case err == nil: + case errors.Is(err, http_range.ErrNoOverlap): if size == 0 { // Some clients add a Range header to all requests to // limit the size of the response. If the file is empty, @@ -105,7 +105,7 @@ func ServeHTTP(w http.ResponseWriter, r *http.Request, name string, modTime time return } - if sumRangesSize(ranges) > size || size < 0 { + if sumRangesSize(ranges) > size { // The total number of bytes in all the ranges is larger than the size of the file // or unknown file size, ignore the range request. ranges = nil From b2791bd7248cebc55a3d1cf72d96dace36fad27f Mon Sep 17 00:00:00 2001 From: Mmx Date: Sun, 1 Sep 2024 18:27:41 +0800 Subject: [PATCH 2/2] fix(webdav): HttpServe memory leak --- internal/net/serve.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/net/serve.go b/internal/net/serve.go index a93c7994712..0eb8cbb8866 100644 --- a/internal/net/serve.go +++ b/internal/net/serve.go @@ -174,6 +174,7 @@ func ServeHTTP(w http.ResponseWriter, r *http.Request, name string, modTime time pw.Close() }() } + defer sendContent.Close() w.Header().Set("Accept-Ranges", "bytes") if w.Header().Get("Content-Encoding") == "" { @@ -192,7 +193,6 @@ func ServeHTTP(w http.ResponseWriter, r *http.Request, name string, modTime time http.Error(w, err.Error(), http.StatusInternalServerError) } } - //defer sendContent.Close() } func ProcessHeader(origin, override http.Header) http.Header { result := http.Header{}