Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: http trace interceptor not keeping original HttpBody properties and LogMode not behaving as expected #1035

Merged
merged 3 commits into from
Feb 12, 2024

Conversation

aajtodd
Copy link
Contributor

@aajtodd aajtodd commented Feb 12, 2024

Issue #

fixes awslabs/aws-sdk-kotlin#1198

Description of changes

  • fix: Preserve the original HttpBody properties like content length from the original HttpBody when duplicating it. The issue in awslabs/aws-sdk-kotlin#1198 seems to have been caused by the fact that the original body was an AwsChunked body with a transfer-encoding: chunked header. When we replace the body during the trace call it was replaced with a non-equivalent in-memory byte array body which always has a content length.
  • fix: LogRequestWithBody and LogResponseWithBody should imply LogRequest and LogResponse respectively. I discovered this trying to debug this issue and seeing the incorrect behaviors for dumping the canonical request from S3

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@aajtodd aajtodd requested a review from a team as a code owner February 12, 2024 15:38
Comment on lines 113 to 117
request.headers.entries()
.filterNot { it.key in skip }
.forEach {
buffer.writeUtf8(it.value.joinToString(separator = ";", prefix = "${it.key}: ", postfix = "\r\n"))
.forEach { entry ->
buffer.writeUtf8(entry.value.joinToString(separator = ";", prefix = "${entry.key}: ", postfix = "\r\n"))
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style: Consider using a destructured lambda declaration:

        .forEach { (key, value) ->
            buffer.writeUtf8(value.joinToString(separator = ";", prefix = "$key: ", postfix = "\r\n"))

val expectedWithContent = "$expectedNoContent$content"
assertEquals(expectedWithContent, actualWithContent)

val actualReplacedContent = builder.body.readAll()?.decodeToString() ?: fail("expected content")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Replace fail with assertNotNull:

val actualReplacedContent = assertNotNull(builder.body.readAll(), "expected content").decodeToString()

Copy link

Quality Gate Passed Quality Gate passed

Issues
0 New issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@aajtodd aajtodd merged commit db1d4d4 into main Feb 12, 2024
13 checks passed
@aajtodd aajtodd deleted the fix-sdk-1198 branch February 12, 2024 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sending a PutObject request with checksum fails if LogMode is set to LogRequestWithBody
4 participants