Skip to content

Commit 41de815

Browse files
committed
correctly calculate unsigned chunk header size
1 parent b04cf1b commit 41de815

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

runtime/auth/aws-signing-common/common/src/aws/smithy/kotlin/runtime/auth/awssigning/AwsChunkedSource.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public class AwsChunkedSource(
4949
override fun read(sink: SdkBuffer, limit: Long): Long {
5050
require(limit >= 0L) { "Invalid limit ($limit) must be >= 0L" }
5151
// COROUTINE SAFETY: runBlocking is allowed here because SdkSource is a synchronous blocking interface
52+
53+
// reset metadata bytes counter
54+
chunkReader.chunkMetadataBytes = 0
5255
val isChunkValid = runBlocking {
5356
chunkReader.ensureValidChunk()
5457
}

runtime/auth/aws-signing-common/common/src/aws/smithy/kotlin/runtime/auth/awssigning/internal/AwsChunkedReader.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ internal class AwsChunkedReader(
7373
internal suspend fun ensureValidChunk(): Boolean {
7474
// check if the current chunk is still valid
7575
if (chunk.size > 0L) {
76-
// reset metadata bytes counter as only first read of a chunk contains metadata
77-
chunkMetadataBytes = 0L
7876
return true
7977
}
8078

@@ -188,7 +186,7 @@ internal class AwsChunkedReader(
188186
*/
189187
private suspend fun getUnsignedChunk(data: SdkBuffer? = null): SdkBuffer? {
190188
val bodyBuffer = data ?: stream.readChunk() ?: return null
191-
189+
val bodyBytes = bodyBuffer.size
192190
val unsignedChunk = SdkBuffer()
193191

194192
// headers
@@ -197,7 +195,7 @@ internal class AwsChunkedReader(
197195
writeUtf8("\r\n")
198196
writeAll(bodyBuffer) // append the body
199197
}
200-
chunkMetadataBytes += unsignedChunk.size - bodyBuffer.size
198+
chunkMetadataBytes += unsignedChunk.size - bodyBytes
201199
return unsignedChunk
202200
}
203201

0 commit comments

Comments
 (0)