Handled possible short writes to httpResponseWriter (#1804)

* XL: Handled possible short writes to httpResponseWriter

* Added tests for Range Header combinations
This commit is contained in:
Krishnan Parthasarathi
2016-05-30 23:57:15 +05:30
committed by Harshavardhana
parent b466f27705
commit 967c2b2940
3 changed files with 30 additions and 20 deletions
+20 -11
View File
@@ -920,18 +920,27 @@ func (s *MyAPIXLSuite) TestPartialContent(c *C) {
c.Assert(response.StatusCode, Equals, http.StatusOK)
// Prepare request
request, err = s.newRequest("GET", testAPIXLServer.URL+"/partial-content/bar", 0, nil)
c.Assert(err, IsNil)
request.Header.Add("Range", "bytes=6-7")
var table = []struct {
byteRange string
expectedString string
}{
{"6-7", "Wo"},
{"6-", "World"},
{"-7", "o World"},
}
for _, t := range table {
request, err = s.newRequest("GET", testAPIXLServer.URL+"/partial-content/bar", 0, nil)
c.Assert(err, IsNil)
request.Header.Add("Range", "bytes="+t.byteRange)
client = http.Client{}
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusPartialContent)
partialObject, err := ioutil.ReadAll(response.Body)
c.Assert(err, IsNil)
c.Assert(string(partialObject), Equals, "Wo")
client = http.Client{}
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusPartialContent)
partialObject, err := ioutil.ReadAll(response.Body)
c.Assert(err, IsNil)
c.Assert(string(partialObject), Equals, t.expectedString)
}
}
func (s *MyAPIXLSuite) TestListObjectsHandlerErrors(c *C) {