Skip to content

Commit b2e6f61

Browse files
committed
Re-add support for http body dot bytes response checksusms
1 parent db65d74 commit b2e6f61

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

runtime/protocol/http-client/common/src/aws/smithy/kotlin/runtime/http/interceptors/FlexibleChecksumsResponseInterceptor.kt

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import aws.smithy.kotlin.runtime.client.config.HttpChecksumConfigOption
1212
import aws.smithy.kotlin.runtime.collections.AttributeKey
1313
import aws.smithy.kotlin.runtime.hashing.toHashFunction
1414
import aws.smithy.kotlin.runtime.http.HttpBody
15+
import aws.smithy.kotlin.runtime.http.readAll
1516
import aws.smithy.kotlin.runtime.http.request.HttpRequest
1617
import aws.smithy.kotlin.runtime.http.response.HttpResponse
1718
import aws.smithy.kotlin.runtime.http.response.copy
@@ -82,14 +83,33 @@ public class FlexibleChecksumsResponseInterceptor<I>(
8283
.removePrefix("x-amz-checksum-")
8384
.toHashFunction() ?: throw ClientException("Could not parse checksum algorithm from header $checksumHeader")
8485

85-
logger.debug { "Validating checksum during deserialization from $checksumHeader" }
86-
87-
// Wrap the response body in a hashing body
88-
return context.protocolResponse.copy(
89-
body = context.protocolResponse.body
90-
.toHashingBody(checksumAlgorithm, context.protocolResponse.body.contentLength)
91-
.toChecksumValidatingBody(serviceChecksumValue),
92-
)
86+
when (val bodyType = context.protocolResponse.body) {
87+
is HttpBody.Bytes -> {
88+
logger.debug { "Validating checksum before deserialization from $checksumHeader" }
89+
90+
checksumAlgorithm.update(
91+
context.protocolResponse.body.readAll() ?: byteArrayOf(),
92+
)
93+
val sdkChecksumValue = checksumAlgorithm.digest().encodeBase64String()
94+
95+
validateAndThrow(
96+
serviceChecksumValue,
97+
sdkChecksumValue,
98+
)
99+
100+
return context.protocolResponse
101+
}
102+
is HttpBody.SourceContent, is HttpBody.ChannelContent -> {
103+
logger.debug { "Validating checksum during deserialization from $checksumHeader" }
104+
105+
return context.protocolResponse.copy(
106+
body = context.protocolResponse.body
107+
.toHashingBody(checksumAlgorithm, context.protocolResponse.body.contentLength)
108+
.toChecksumValidatingBody(serviceChecksumValue),
109+
)
110+
}
111+
else -> throw IllegalStateException("Http body type '$bodyType' is not supported for flexible checksums.")
112+
}
93113
}
94114
}
95115

0 commit comments

Comments
 (0)