TestRangeRequest verifies that Range header returns partial content
()
| 125 | |
| 126 | // TestRangeRequest verifies that Range header returns partial content |
| 127 | func (s *ReaderSuite) TestRangeRequest() { |
| 128 | ctx := s.T().Context() |
| 129 | reqHeader := make(http.Header) |
| 130 | reqHeader.Set(httpheaders.Range, "bytes=10-19") |
| 131 | |
| 132 | response, err := s.Storage().GetObject(ctx, reqHeader, s.TestContainer, s.TestObjectKey, "") |
| 133 | s.Require().NoError(err) |
| 134 | |
| 135 | if !s.SkipPartialContentChecks { |
| 136 | s.Require().Equal(http.StatusPartialContent, response.Status) |
| 137 | |
| 138 | expectedRange := fmt.Sprintf("bytes 10-19/%d", len(s.TestData)) |
| 139 | s.Require().Equal(expectedRange, response.Headers.Get(httpheaders.ContentRange)) |
| 140 | } |
| 141 | |
| 142 | s.Require().Equal("10", response.Headers.Get(httpheaders.ContentLength)) |
| 143 | s.Require().NotNil(response.Body) |
| 144 | |
| 145 | // Read and verify the actual content (bytes 10-19 from testData) |
| 146 | buf := make([]byte, 10) |
| 147 | n, _ := response.Body.Read(buf) |
| 148 | s.Require().Equal(10, n) |
| 149 | s.Require().Equal(s.TestData[10:20], buf) |
| 150 | |
| 151 | response.Body.Close() |
| 152 | } |
| 153 | |
| 154 | // TestObjectNotFound verifies that requesting a non-existent object returns 404 |
| 155 | func (s *ReaderSuite) TestObjectNotFound() { |