signv4: Read always returns EOF when stream ends (#3692)

When EOF is reached, further calls of Read() doesn't return io.EOF
but continue to work as it expects to have more data, this PR fixes
the behavior
This commit is contained in:
Anis Elleuch
2017-02-06 23:19:27 +01:00
committed by Harshavardhana
parent 45d9cfa0c5
commit 70e70446bb
2 changed files with 32 additions and 11 deletions

View File

@@ -221,6 +221,7 @@ const (
readChunkTrailer
readChunk
verifyChunk
eofChunk
)
func (cs chunkState) String() string {
@@ -234,6 +235,9 @@ func (cs chunkState) String() string {
stateString = "readChunk"
case verifyChunk:
stateString = "verifyChunk"
case eofChunk:
stateString = "eofChunk"
}
return stateString
}
@@ -309,10 +313,13 @@ func (cr *s3ChunkedReader) Read(buf []byte) (n int, err error) {
// this follows the chaining.
cr.seedSignature = newSignature
cr.chunkSHA256Writer.Reset()
cr.state = readChunkHeader
if cr.lastChunk {
return n, nil
cr.state = eofChunk
} else {
cr.state = readChunkHeader
}
case eofChunk:
return n, io.EOF
}
}
}