Skip to content

Commit c6b0442

Browse files
committed
Centralize the default checksum in a single place
1 parent fe0a3a3 commit c6b0442

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpRequestChecksumDecorator.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ internal fun RuntimeConfig.awsInlineableHttpRequestChecksum() =
5757
class HttpRequestChecksumDecorator : ClientCodegenDecorator {
5858
override val name: String = "HttpRequestChecksum"
5959
override val order: Byte = 0
60-
private val defaultAlgorithm = "CRC32"
6160

6261
override fun operationCustomizations(
6362
codegenContext: ClientCodegenContext,
@@ -103,6 +102,11 @@ private fun HttpChecksumTrait.requestAlgorithmMember(
103102
return codegenContext.symbolProvider.toMemberName(checksumAlgorithmMemberShape)
104103
}
105104

105+
// This is the single place where the default algorithm is set. It must be all uppercased.
106+
// There is some special logic in HttpChecksumTest and in the http_request_checksum inlineable
107+
// for testing the default case, if you change this value you will have to update that logic as well.
108+
const val defaultAlgorithm = "CRC32"
109+
106110
/**
107111
* Extract the name of the operation's input member that indicates which checksum algorithm to use
108112
*/
@@ -116,8 +120,8 @@ private fun HttpChecksumTrait.checksumAlgorithmToStr(
116120

117121
return {
118122
if (requestAlgorithmMember == null && isRequestChecksumRequired) {
119-
// Checksums are required but a user can't set one, so we set crc32 for them
120-
rust("""let checksum_algorithm = Some("crc32");""")
123+
// Checksums are required but a user can't set one, so we set the default for them
124+
rust("""let checksum_algorithm = Some("${defaultAlgorithm.lowercase()}");""")
121125
} else {
122126
// Use checksum algo set by user
123127
rust("""let checksum_algorithm = checksum_algorithm.map(|algorithm| algorithm.as_str());""")
@@ -209,7 +213,7 @@ class HttpRequestChecksumCustomization(
209213
210214
// If the request is presigned we do not set a default.
211215
// If the RequestChecksumCalculation is WhenSupported and the user has not set a checksum value or algo
212-
// we default to Crc32. If it is WhenRequired and a checksum is required by the trait and the user has not
216+
// we set the default. If it is WhenRequired and a checksum is required by the trait and the user has not
213217
// set a checksum value or algo we also set the default. In all other cases we do nothing.
214218
match (
215219
request_checksum_calculation,
@@ -221,7 +225,7 @@ class HttpRequestChecksumCustomization(
221225
(_, _, _, _, true) => {}
222226
(#{RequestChecksumCalculation}::WhenSupported, _, false, false, _)
223227
| (#{RequestChecksumCalculation}::WhenRequired, true, false, false, _) => {
224-
request.headers_mut().insert(${requestAlgoHeader.dq()}, "CRC32");
228+
request.headers_mut().insert(${requestAlgoHeader.dq()}, "$defaultAlgorithm");
225229
}
226230
_ => {},
227231
}

0 commit comments

Comments
 (0)