Skip to content

Commit f8ad6b1

Browse files
committed
Fixing partial object get response to fetch content on 206 response code
1 parent 95a7b9e commit f8ad6b1

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/ds3/ds3Client_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,34 @@ func TestGetObject(t *testing.T) {
323323
ds3Testing.AssertString(t, "Response", stringResponse, string(bs))
324324
}
325325

326+
func TestGetPartialObject(t *testing.T) {
327+
stringResponse := "object contents"
328+
329+
// Create and run the mocked client.
330+
requestHeaders := &http.Header{}
331+
requestHeaders.Add("Range", "bytes=1-5")
332+
333+
response, err := mockedClient(t).
334+
Expecting(HTTP_VERB_GET, "/bucketName/object", &url.Values{}, requestHeaders, nil).
335+
Returning(206, stringResponse, nil).
336+
GetObject(models.NewGetObjectRequest("bucketName", "object").WithRange(1, 5))
337+
338+
// Check the error result.
339+
ds3Testing.AssertNilError(t, err)
340+
341+
// Check the response value.
342+
if response == nil {
343+
t.Fatal("Response was unexpectedly nil.")
344+
}
345+
if response.Content == nil {
346+
t.Fatal("Response content was unexpectedly nil.")
347+
}
348+
defer response.Content.Close()
349+
bs, readErr := ioutil.ReadAll(response.Content)
350+
ds3Testing.AssertNilError(t, readErr)
351+
ds3Testing.AssertString(t, "Response", stringResponse, string(bs))
352+
}
353+
326354
func TestGetObjectRange(t *testing.T) {
327355
stringResponse := "object contents"
328356
requestHeaders := &http.Header{"Range": []string{"bytes=20-179"}}

src/ds3/models/getObjectResponse.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func NewGetObjectResponse(webResponse WebResponse) (*GetObjectResponse, error) {
3232
case 200:
3333
return &GetObjectResponse{ Content: webResponse.Body(), Headers: webResponse.Header() }, nil
3434
case 206:
35-
return &GetObjectResponse{Headers: webResponse.Header()}, nil
35+
return &GetObjectResponse{ Content: webResponse.Body(), Headers: webResponse.Header() }, nil
3636
default:
3737
return nil, buildBadStatusCodeError(webResponse, expectedStatusCodes)
3838
}

0 commit comments

Comments
 (0)