Skip to content

Commit b6d800b

Browse files
authored
fix: expand test coverage of engine implementations to include empty body repr (#667)
1 parent 65027f8 commit b6d800b

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"id": "04cb3052-4479-4b00-a08c-f7b5fbe1d59a",
3+
"type": "bugfix",
4+
"description": "Fix ktor engine representation of empty payload",
5+
"issues": [
6+
"awslabs/aws-sdk-kotlin#638"
7+
]
8+
}

runtime/protocol/http-client-engines/http-client-engine-ktor/common/src/aws/smithy/kotlin/runtime/http/engine/ktor/KtorEngine.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package aws.smithy.kotlin.runtime.http.engine.ktor
66

77
import aws.smithy.kotlin.runtime.client.ExecutionContext
88
import aws.smithy.kotlin.runtime.http.Headers
9+
import aws.smithy.kotlin.runtime.http.HttpBody
910
import aws.smithy.kotlin.runtime.http.HttpStatusCode
1011
import aws.smithy.kotlin.runtime.http.engine.*
1112
import aws.smithy.kotlin.runtime.http.operation.withContext
@@ -121,7 +122,12 @@ class KtorEngine(
121122
waiter.signal()
122123
}
123124

124-
val body = KtorHttpBody(httpResp.contentLength(), content)
125+
val contentLength = httpResp.contentLength()
126+
val body = if (contentLength == 0L) {
127+
HttpBody.Empty
128+
} else {
129+
KtorHttpBody(httpResp.contentLength(), content)
130+
}
125131

126132
// copy the headers so that we no longer depend on the underlying ktor HttpResponse object
127133
// outside of the body content (which will signal once read that it is safe to exit the block)

runtime/protocol/http-client-engines/test-suite/common/test/aws/smithy/kotlin/runtime/http/test/DownloadTest.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,27 @@ class DownloadTest : AbstractEngineTest() {
116116
}
117117
}
118118
}
119+
120+
@Test
121+
fun testEmptyPayloadRepresentation() = testEngines {
122+
// We have behavior built on top of how an empty payload is represented, ensure it is consitent
123+
// across engines, see https://github.com/awslabs/aws-sdk-kotlin/issues/638
124+
test { env, client ->
125+
val req = HttpRequest {
126+
testSetup(env)
127+
url.path = "/download/empty"
128+
}
129+
130+
val call = client.call(req)
131+
try {
132+
assertEquals(HttpStatusCode.OK, call.response.status)
133+
assertEquals(0, call.response.body.contentLength, "${client.engine}")
134+
135+
val body = call.response.body
136+
assertIs<HttpBody.Empty>(body, "${client.engine}")
137+
} finally {
138+
call.complete()
139+
}
140+
}
141+
}
119142
}

runtime/protocol/http-client-engines/test-suite/jvm/src/aws/smithy/kotlin/runtime/http/test/suite/Downloads.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ internal fun Application.downloadTests() {
5555

5656
call.respond(content)
5757
}
58+
59+
get("/empty") {
60+
call.response.status(HttpStatusCode.OK)
61+
call.response.header("x-foo", "foo")
62+
call.response.header("x-bar", "bar")
63+
}
5864
}
5965
}
6066
}

0 commit comments

Comments
 (0)