From 3ae24a20557d74372beeca9ac29efebdd13a6494 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 15 Sep 2025 12:35:24 -0400 Subject: [PATCH 1/8] Override `Content-Length` rather than appending --- .../aws/smithy/kotlin/runtime/http/engine/crt/RequestUtil.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/protocol/http-client-engines/http-client-engine-crt/jvm/src/aws/smithy/kotlin/runtime/http/engine/crt/RequestUtil.kt b/runtime/protocol/http-client-engines/http-client-engine-crt/jvm/src/aws/smithy/kotlin/runtime/http/engine/crt/RequestUtil.kt index 5708f111b0..73f7d605a3 100644 --- a/runtime/protocol/http-client-engines/http-client-engine-crt/jvm/src/aws/smithy/kotlin/runtime/http/engine/crt/RequestUtil.kt +++ b/runtime/protocol/http-client-engines/http-client-engine-crt/jvm/src/aws/smithy/kotlin/runtime/http/engine/crt/RequestUtil.kt @@ -68,7 +68,7 @@ internal fun HttpRequest.toCrtRequest(callContext: CoroutineContext): aws.sdk.ko } val contentLength = body.contentLength?.takeIf { it >= 0 }?.toString() ?: headers[CONTENT_LENGTH_HEADER] - contentLength?.let { crtHeaders.append(CONTENT_LENGTH_HEADER, it) } + contentLength?.let { crtHeaders[CONTENT_LENGTH_HEADER] = it } return aws.sdk.kotlin.crt.http.HttpRequest(method.name, url.requestRelativePath, crtHeaders.build(), bodyStream) } From bcc155d032b6043e42a7dcf594826d94dbabd93d Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 15 Sep 2025 12:36:35 -0400 Subject: [PATCH 2/8] Changelog --- .changes/4855cecf-6a96-4622-b7ff-5d09e54f6564.json | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changes/4855cecf-6a96-4622-b7ff-5d09e54f6564.json diff --git a/.changes/4855cecf-6a96-4622-b7ff-5d09e54f6564.json b/.changes/4855cecf-6a96-4622-b7ff-5d09e54f6564.json new file mode 100644 index 0000000000..2a18809a6d --- /dev/null +++ b/.changes/4855cecf-6a96-4622-b7ff-5d09e54f6564.json @@ -0,0 +1,5 @@ +{ + "id": "4855cecf-6a96-4622-b7ff-5d09e54f6564", + "type": "bugfix", + "description": "Override `Content-Length` header rather than appending in `CrtHttpEngine`" +} \ No newline at end of file From b4d83ea09a635c19c13903fd906445260c22292b Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 15 Sep 2025 12:37:14 -0400 Subject: [PATCH 3/8] Test invalid changelog --- .changes/749b6a83-041f-43f9-b1a2-8c525146e6e4.json | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changes/749b6a83-041f-43f9-b1a2-8c525146e6e4.json diff --git a/.changes/749b6a83-041f-43f9-b1a2-8c525146e6e4.json b/.changes/749b6a83-041f-43f9-b1a2-8c525146e6e4.json new file mode 100644 index 0000000000..c7a31ad81d --- /dev/null +++ b/.changes/749b6a83-041f-43f9-b1a2-8c525146e6e4.json @@ -0,0 +1,5 @@ +{ + "id": "749b6a83-041f-43f9-b1a2-8c525146e6e4", + "typ": "misc", + "description": "Testing invalid changelog" +} \ No newline at end of file From 2d17b2e8a71840e7b0f0bc6967360680a17603ce Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 15 Sep 2025 12:40:33 -0400 Subject: [PATCH 4/8] Delete invalid changelog --- .changes/749b6a83-041f-43f9-b1a2-8c525146e6e4.json | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 .changes/749b6a83-041f-43f9-b1a2-8c525146e6e4.json diff --git a/.changes/749b6a83-041f-43f9-b1a2-8c525146e6e4.json b/.changes/749b6a83-041f-43f9-b1a2-8c525146e6e4.json deleted file mode 100644 index c7a31ad81d..0000000000 --- a/.changes/749b6a83-041f-43f9-b1a2-8c525146e6e4.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "id": "749b6a83-041f-43f9-b1a2-8c525146e6e4", - "typ": "misc", - "description": "Testing invalid changelog" -} \ No newline at end of file From 54fd671444151e1fb485d9aefebf3d99569ba01a Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 15 Sep 2025 12:42:17 -0400 Subject: [PATCH 5/8] Override -> Overwrite --- .changes/4855cecf-6a96-4622-b7ff-5d09e54f6564.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changes/4855cecf-6a96-4622-b7ff-5d09e54f6564.json b/.changes/4855cecf-6a96-4622-b7ff-5d09e54f6564.json index 2a18809a6d..6c781606fe 100644 --- a/.changes/4855cecf-6a96-4622-b7ff-5d09e54f6564.json +++ b/.changes/4855cecf-6a96-4622-b7ff-5d09e54f6564.json @@ -1,5 +1,5 @@ { "id": "4855cecf-6a96-4622-b7ff-5d09e54f6564", "type": "bugfix", - "description": "Override `Content-Length` header rather than appending in `CrtHttpEngine`" + "description": "Overwrite `Content-Length` header rather than appending in `CrtHttpEngine`" } \ No newline at end of file From 1b0ff524091508933c1809ada486003b02afd31f Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Tue, 23 Sep 2025 12:16:34 -0400 Subject: [PATCH 6/8] Add Content-Length header tests --- .../http/engine/crt/RequestUtilTest.kt | 23 +++++++++++++++++++ .../http/engine/okhttp/OkHttpRequestTest.kt | 17 ++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/runtime/protocol/http-client-engines/http-client-engine-crt/jvm/test/aws/smithy/kotlin/runtime/http/engine/crt/RequestUtilTest.kt b/runtime/protocol/http-client-engines/http-client-engine-crt/jvm/test/aws/smithy/kotlin/runtime/http/engine/crt/RequestUtilTest.kt index 25db47c70f..9651cff068 100644 --- a/runtime/protocol/http-client-engines/http-client-engine-crt/jvm/test/aws/smithy/kotlin/runtime/http/engine/crt/RequestUtilTest.kt +++ b/runtime/protocol/http-client-engines/http-client-engine-crt/jvm/test/aws/smithy/kotlin/runtime/http/engine/crt/RequestUtilTest.kt @@ -4,9 +4,17 @@ */ package aws.smithy.kotlin.runtime.http.engine.crt +import aws.smithy.kotlin.runtime.content.ByteStream +import aws.smithy.kotlin.runtime.http.Headers +import aws.smithy.kotlin.runtime.http.request.HttpRequest +import aws.smithy.kotlin.runtime.http.HttpMethod +import aws.smithy.kotlin.runtime.http.toHttpBody +import aws.smithy.kotlin.runtime.net.url.Url +import kotlinx.coroutines.test.runTest import kotlin.test.Test import kotlin.test.assertFalse import kotlin.test.assertTrue +import kotlin.test.assertEquals class RequestUtilTest { @Test @@ -42,4 +50,19 @@ class RequestUtilTest { assertFalse(isRetryable(code, name), "Expected $name to not be retryable!") } } + + @Test + fun testContentLengthHeader() = runTest { + val data = "a".repeat(100) + + val request = HttpRequest( + HttpMethod.POST, + url = Url.parse("https://notarealurl.com"), + headers = Headers { set("Content-Length", data.length.toString()) }, + body = ByteStream.fromString(data).toHttpBody() + ) + + val crtRequest = request.toCrtRequest(coroutineContext) + assertEquals(listOf(data.length.toString()), crtRequest.headers.getAll("Content-Length")) + } } diff --git a/runtime/protocol/http-client-engines/http-client-engine-okhttp/jvm/test/aws/smithy/kotlin/runtime/http/engine/okhttp/OkHttpRequestTest.kt b/runtime/protocol/http-client-engines/http-client-engine-okhttp/jvm/test/aws/smithy/kotlin/runtime/http/engine/okhttp/OkHttpRequestTest.kt index 16f6773008..760a947308 100644 --- a/runtime/protocol/http-client-engines/http-client-engine-okhttp/jvm/test/aws/smithy/kotlin/runtime/http/engine/okhttp/OkHttpRequestTest.kt +++ b/runtime/protocol/http-client-engines/http-client-engine-okhttp/jvm/test/aws/smithy/kotlin/runtime/http/engine/okhttp/OkHttpRequestTest.kt @@ -5,6 +5,7 @@ package aws.smithy.kotlin.runtime.http.engine.okhttp +import aws.smithy.kotlin.runtime.content.ByteStream import aws.smithy.kotlin.runtime.http.* import aws.smithy.kotlin.runtime.http.engine.internal.HttpClientMetrics import aws.smithy.kotlin.runtime.http.request.HttpRequest @@ -71,6 +72,22 @@ class OkHttpRequestTest { assertEquals(listOf("bar", "baz"), actual.headers("FoO")) } + @Test + fun itConvertsContentLengthHeader() { + val data = "a".repeat(100) + val url = Url.parse("https://aws.amazon.com") + val headers = Headers { + append("Content-Length", data.length.toString()) + } + val request = HttpRequest(HttpMethod.POST, url, headers, ByteStream.fromString(data).toHttpBody()) + + val execContext = ExecutionContext() + val actual = request.toOkHttpRequest(execContext, EmptyCoroutineContext, testMetrics) + + assertTrue(actual.headers.size >= 1) + assertEquals(listOf(data.length.toString()), actual.headers("Content-Length")) + } + @Test fun itSupportsNonAsciiHeaderValues() { val url = Url.parse("https://aws.amazon.com") From 70b724f53e051072112423882dc349183f384fcc Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Tue, 23 Sep 2025 12:21:50 -0400 Subject: [PATCH 7/8] ktlint --- .../kotlin/runtime/http/engine/crt/RequestUtilTest.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/protocol/http-client-engines/http-client-engine-crt/jvm/test/aws/smithy/kotlin/runtime/http/engine/crt/RequestUtilTest.kt b/runtime/protocol/http-client-engines/http-client-engine-crt/jvm/test/aws/smithy/kotlin/runtime/http/engine/crt/RequestUtilTest.kt index 9651cff068..cb2d338588 100644 --- a/runtime/protocol/http-client-engines/http-client-engine-crt/jvm/test/aws/smithy/kotlin/runtime/http/engine/crt/RequestUtilTest.kt +++ b/runtime/protocol/http-client-engines/http-client-engine-crt/jvm/test/aws/smithy/kotlin/runtime/http/engine/crt/RequestUtilTest.kt @@ -6,15 +6,15 @@ package aws.smithy.kotlin.runtime.http.engine.crt import aws.smithy.kotlin.runtime.content.ByteStream import aws.smithy.kotlin.runtime.http.Headers -import aws.smithy.kotlin.runtime.http.request.HttpRequest import aws.smithy.kotlin.runtime.http.HttpMethod +import aws.smithy.kotlin.runtime.http.request.HttpRequest import aws.smithy.kotlin.runtime.http.toHttpBody import aws.smithy.kotlin.runtime.net.url.Url import kotlinx.coroutines.test.runTest import kotlin.test.Test +import kotlin.test.assertEquals import kotlin.test.assertFalse import kotlin.test.assertTrue -import kotlin.test.assertEquals class RequestUtilTest { @Test @@ -59,7 +59,7 @@ class RequestUtilTest { HttpMethod.POST, url = Url.parse("https://notarealurl.com"), headers = Headers { set("Content-Length", data.length.toString()) }, - body = ByteStream.fromString(data).toHttpBody() + body = ByteStream.fromString(data).toHttpBody(), ) val crtRequest = request.toCrtRequest(coroutineContext) From 2cd217d845f863129e58b312fd007e8551b56237 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Tue, 23 Sep 2025 12:22:49 -0400 Subject: [PATCH 8/8] bump to latest version of aws-kotlin-repo-tools --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d3c4d7f04a..8b60cc05ea 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,7 +2,7 @@ kotlin-version = "2.2.0" dokka-version = "2.0.0" -aws-kotlin-repo-tools-version = "0.4.44" +aws-kotlin-repo-tools-version = "0.4.56" # libs coroutines-version = "1.10.2"