Skip to content

Commit

Permalink
fix: avoid IncompleteRead on completed partial reads (#1827)
Browse files Browse the repository at this point in the history
* fix: avoid IncompleteRead on completed partial reads

Fix a bug in which the server would return a 416 reply with an
empty body declaring a Content-Length of 1.

Closes #1761

Signed-off-by: Francesco Canovai <francesco.canovai@enterprisedb.com>

* fakestorage: add a test for invalid range

---------

Signed-off-by: Francesco Canovai <francesco.canovai@enterprisedb.com>
Co-authored-by: francisco souza <108725+fsouza@users.noreply.github.com>
  • Loading branch information
fcanovai and fsouza authored Jan 3, 2025
1 parent 3151091 commit d66abd9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion fakestorage/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ func (s *Server) handleRange(obj StreamingObject, r *http.Request) (ranged bool,
// Length: 40, Range: bytes=50-
case start >= obj.Size:
// This IS a ranged request, but it ISN'T satisfiable.
return true, 0, 0, false
return true, 0, -1, false
// Negative range, ignore range and return all content.
// Examples:
// Length: 40, Range: bytes=30-20
Expand Down
28 changes: 28 additions & 0 deletions fakestorage/object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,34 @@ func TestServerClientObjectRangeReader(t *testing.T) {
})
}

func TestServerClientObjectRangeReaderInvalid(t *testing.T) {
const (
bucketName = "some-bucket"
objectName = "items/data.txt"
content = "some really nice but long content stored in my object"
contentType = "text/plain; charset=iso-8859"
)
objs := []Object{
{
ObjectAttrs: ObjectAttrs{
BucketName: bucketName,
Name: objectName,
ContentType: contentType,
},
Content: []byte(content),
},
}

runServersTest(t, runServersOptions{objs: objs}, func(t *testing.T, server *Server) {
client := server.Client()
objHandle := client.Bucket(bucketName).Object(objectName)
_, err := objHandle.NewRangeReader(context.TODO(), 500, 10)
if err == nil {
t.Fatal("unexpected <nil> error")
}
})
}

func TestServerClientObjectReaderAfterCreateObject(t *testing.T) {
const (
bucketName = "staging-bucket"
Expand Down

0 comments on commit d66abd9

Please sign in to comment.