Skip to content

Commit

Permalink
[bugfix] Properly handle range > content-length (#1979)
Browse files Browse the repository at this point in the history
This makes the serveFileRange function return the entire file
if suffix-range is larger than content-length in compliance with RFC9110

Co-authored-by: mae <git@badat.dev>
  • Loading branch information
MaeIsBad and MaeIsBad authored Jul 12, 2023
1 parent ca5492b commit 0d267fd
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions internal/api/fileserver/servefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,9 @@ func serveFileRange(rw http.ResponseWriter, r *http.Request, src io.Reader, rng
}

if end > size {
// This range exceeds length of the file, therefore unsatisfiable
rw.Header().Set("Content-Range", "bytes *"+strconv.FormatInt(size, 10))
http.Error(rw, "Unsatisfiable Range", http.StatusRequestedRangeNotSatisfiable)
return
// According to the http spec if end >= size the server should return the rest of the file
// https://www.rfc-editor.org/rfc/rfc9110#section-14.1.2-6
end = size - 1
}
} else {
// No end supplied, implying file end
Expand Down

0 comments on commit 0d267fd

Please sign in to comment.