Skip to content

Commit

Permalink
track upstream removal of ByteArrayContent
Browse files Browse the repository at this point in the history
  • Loading branch information
aajtodd committed Oct 4, 2023
1 parent 78144d4 commit aaa8846
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import aws.sdk.kotlin.runtime.config.AwsSdkSetting
import aws.smithy.kotlin.runtime.auth.awscredentials.Credentials
import aws.smithy.kotlin.runtime.auth.awscredentials.CredentialsProviderException
import aws.smithy.kotlin.runtime.http.Headers
import aws.smithy.kotlin.runtime.http.HttpBody
import aws.smithy.kotlin.runtime.http.HttpMethod
import aws.smithy.kotlin.runtime.http.HttpStatusCode
import aws.smithy.kotlin.runtime.http.content.ByteArrayContent
import aws.smithy.kotlin.runtime.http.request.HttpRequest
import aws.smithy.kotlin.runtime.http.request.HttpRequestBuilder
import aws.smithy.kotlin.runtime.http.request.header
Expand Down Expand Up @@ -54,15 +54,15 @@ class EcsCredentialsProviderTest {
"Expiration" : "${expectedExpiration.format(TimestampFormat.ISO_8601)}"
}
""".encodeToByteArray()
return HttpResponse(HttpStatusCode.OK, Headers.Empty, ByteArrayContent(payload))
return HttpResponse(HttpStatusCode.OK, Headers.Empty, HttpBody.fromBytes(payload))
}

private fun errorResponse(
statusCode: HttpStatusCode = HttpStatusCode.BadRequest,
headers: Headers = Headers.Empty,
body: String = "",
): HttpResponse =
HttpResponse(statusCode, headers, ByteArrayContent(body.encodeToByteArray()))
HttpResponse(statusCode, headers, HttpBody.fromBytes(body.encodeToByteArray()))

private fun ecsRequest(url: String, authToken: String? = null): HttpRequest {
val resolvedUrl = Url.parse(url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import aws.smithy.kotlin.runtime.http.HttpBody
import aws.smithy.kotlin.runtime.http.HttpCall
import aws.smithy.kotlin.runtime.http.HttpMethod
import aws.smithy.kotlin.runtime.http.HttpStatusCode
import aws.smithy.kotlin.runtime.http.content.ByteArrayContent
import aws.smithy.kotlin.runtime.http.engine.HttpClientEngineBase
import aws.smithy.kotlin.runtime.http.engine.HttpClientEngineConfig
import aws.smithy.kotlin.runtime.http.request.HttpRequest
Expand Down Expand Up @@ -241,7 +240,7 @@ class ImdsCredentialsProviderTest {
HttpResponse(
HttpStatusCode.NotFound,
Headers.Empty,
ByteArrayContent(
HttpBody.fromBytes(
"""<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import aws.smithy.kotlin.runtime.auth.awscredentials.Credentials
import aws.smithy.kotlin.runtime.http.Headers
import aws.smithy.kotlin.runtime.http.HttpBody
import aws.smithy.kotlin.runtime.http.HttpStatusCode
import aws.smithy.kotlin.runtime.http.content.ByteArrayContent
import aws.smithy.kotlin.runtime.http.response.HttpResponse
import aws.smithy.kotlin.runtime.httptest.TestConnection
import aws.smithy.kotlin.runtime.httptest.buildTestConnection
Expand Down Expand Up @@ -169,7 +168,7 @@ class SsoCredentialsProviderTest {

val engine = buildTestConnection {
expect(
HttpResponse(HttpStatusCode.OK, Headers.Empty, ByteArrayContent(serviceResp.encodeToByteArray())),
HttpResponse(HttpStatusCode.OK, Headers.Empty, HttpBody.fromBytes(serviceResp.encodeToByteArray())),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ package aws.sdk.kotlin.runtime.auth.credentials
import aws.sdk.kotlin.runtime.auth.credentials.internal.sts.model.RegionDisabledException
import aws.smithy.kotlin.runtime.auth.awscredentials.CredentialsProviderException
import aws.smithy.kotlin.runtime.http.Headers
import aws.smithy.kotlin.runtime.http.HttpBody
import aws.smithy.kotlin.runtime.http.HttpStatusCode
import aws.smithy.kotlin.runtime.http.content.ByteArrayContent
import aws.smithy.kotlin.runtime.http.response.HttpResponse
import aws.smithy.kotlin.runtime.httptest.CallAsserter
import aws.smithy.kotlin.runtime.httptest.buildTestConnection
Expand Down Expand Up @@ -105,7 +105,7 @@ class StsAssumeRoleCredentialsProviderTest {
</ErrorResponse>
"""
val testEngine = buildTestConnection {
expect(HttpResponse(HttpStatusCode.BadRequest, Headers.Empty, ByteArrayContent(errorResponseBody.encodeToByteArray())))
expect(HttpResponse(HttpStatusCode.BadRequest, Headers.Empty, HttpBody.fromBytes(errorResponseBody.encodeToByteArray())))
}

val provider = StsAssumeRoleCredentialsProvider(
Expand All @@ -132,7 +132,7 @@ class StsAssumeRoleCredentialsProviderTest {
</ErrorResponse>
"""
val testEngine = buildTestConnection {
expect(HttpResponse(HttpStatusCode.Forbidden, Headers.Empty, ByteArrayContent(errorResponseBody.encodeToByteArray())))
expect(HttpResponse(HttpStatusCode.Forbidden, Headers.Empty, HttpBody.fromBytes(errorResponseBody.encodeToByteArray())))
}

val provider = StsAssumeRoleCredentialsProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import aws.smithy.kotlin.runtime.http.Headers
import aws.smithy.kotlin.runtime.http.HttpBody
import aws.smithy.kotlin.runtime.http.HttpMethod
import aws.smithy.kotlin.runtime.http.HttpStatusCode
import aws.smithy.kotlin.runtime.http.content.ByteArrayContent
import aws.smithy.kotlin.runtime.http.request.HttpRequestBuilder
import aws.smithy.kotlin.runtime.http.request.url
import aws.smithy.kotlin.runtime.http.response.HttpResponse
Expand Down Expand Up @@ -76,6 +75,6 @@ object StsTestUtils {
</ResponseMetadata>
</AssumeRoleResponse>
""".trimIndent()
return HttpResponse(HttpStatusCode.OK, Headers.Empty, ByteArrayContent(body.encodeToByteArray()))
return HttpResponse(HttpStatusCode.OK, Headers.Empty, HttpBody.fromBytes(body.encodeToByteArray()))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ package aws.sdk.kotlin.runtime.auth.credentials
import aws.smithy.kotlin.runtime.auth.awscredentials.Credentials
import aws.smithy.kotlin.runtime.auth.awscredentials.CredentialsProviderException
import aws.smithy.kotlin.runtime.http.Headers
import aws.smithy.kotlin.runtime.http.HttpBody
import aws.smithy.kotlin.runtime.http.HttpStatusCode
import aws.smithy.kotlin.runtime.http.content.ByteArrayContent
import aws.smithy.kotlin.runtime.http.response.HttpResponse
import aws.smithy.kotlin.runtime.httptest.CallAsserter
import aws.smithy.kotlin.runtime.httptest.TestConnection
Expand Down Expand Up @@ -67,7 +67,7 @@ class StsWebIdentityCredentialsProviderTest {
</AssumeRoleWithWebIdentityResponse>
""".trimIndent()

return HttpResponse(HttpStatusCode.OK, Headers.Empty, ByteArrayContent(body.encodeToByteArray()))
return HttpResponse(HttpStatusCode.OK, Headers.Empty, HttpBody.fromBytes(body.encodeToByteArray()))
}

@Test
Expand Down Expand Up @@ -160,7 +160,7 @@ class StsWebIdentityCredentialsProviderTest {
"""

val testEngine = buildTestConnection {
expect(HttpResponse(HttpStatusCode.BadRequest, Headers.Empty, ByteArrayContent(errorResponseBody.encodeToByteArray())))
expect(HttpResponse(HttpStatusCode.BadRequest, Headers.Empty, HttpBody.fromBytes(errorResponseBody.encodeToByteArray())))
}

val testPlatform = TestPlatformProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
package aws.sdk.kotlin.runtime.config.imds

import aws.smithy.kotlin.runtime.http.Headers
import aws.smithy.kotlin.runtime.http.HttpBody
import aws.smithy.kotlin.runtime.http.HttpMethod
import aws.smithy.kotlin.runtime.http.HttpStatusCode
import aws.smithy.kotlin.runtime.http.content.ByteArrayContent
import aws.smithy.kotlin.runtime.http.request.HttpRequest
import aws.smithy.kotlin.runtime.http.request.url
import aws.smithy.kotlin.runtime.http.response.HttpResponse
Expand All @@ -27,7 +27,7 @@ fun tokenResponse(ttl: Int, token: String): HttpResponse = HttpResponse(
Headers {
append(X_AWS_EC2_METADATA_TOKEN_TTL_SECONDS, ttl.toString())
},
ByteArrayContent(token.encodeToByteArray()),
HttpBody.fromBytes(token.encodeToByteArray()),
)

fun imdsRequest(url: String, token: String): HttpRequest = HttpRequest {
Expand All @@ -39,5 +39,5 @@ fun imdsRequest(url: String, token: String): HttpRequest = HttpRequest {
fun imdsResponse(body: String): HttpResponse = HttpResponse(
HttpStatusCode.OK,
Headers.Empty,
ByteArrayContent(body.encodeToByteArray()),
HttpBody.fromBytes(body.encodeToByteArray()),
)
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ class RestJson1 : JsonHttpBindingProtocolGenerator() {
val target = ctx.model.expectShape(httpPayload.member.target)
writer.withBlock("if (input.#L == null) {", "}", memberName) {
if (target is StructureShape) {
addImport(RuntimeTypes.Http.ByteArrayContent)
write("builder.body = #T(#S.encodeToByteArray())", RuntimeTypes.Http.ByteArrayContent, "{}")
write("builder.body = #T.fromBytes(#S.encodeToByteArray())", RuntimeTypes.Http.HttpBody, "{}")
}
// Content-Type still needs to be set for non-structured payloads
// https://github.com/awslabs/smithy/blob/main/smithy-aws-protocol-tests/model/restJson1/http-content-type.smithy#L174
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ abstract class QueryHttpBindingProtocolGenerator : AwsHttpBindingProtocolGenerat
val service = ctx.model.expectShape<ServiceShape>(ctx.settings.service)
val version = service.version
writer.write("""val content = "Action=$action&Version=$version"""")
writer.write("builder.body = #T(content.encodeToByteArray())", RuntimeTypes.Http.ByteArrayContent)
writer.write("builder.body = #T.fromBytes(content.encodeToByteArray())", RuntimeTypes.Http.HttpBody)
} else {
super.renderSerializeHttpBody(ctx, op, writer)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package aws.sdk.kotlin.services.glacier.internal
import aws.smithy.kotlin.runtime.content.ByteStream
import aws.smithy.kotlin.runtime.hashing.HashFunction
import aws.smithy.kotlin.runtime.hashing.Sha256
import aws.smithy.kotlin.runtime.http.content.ByteArrayContent
import aws.smithy.kotlin.runtime.http.toHttpBody
import aws.smithy.kotlin.runtime.io.SdkBuffer
import aws.smithy.kotlin.runtime.io.SdkByteChannel
Expand Down Expand Up @@ -37,7 +36,7 @@ class TreeHasherTest {
val chunkSize = 3
val hasher = TreeHasherImpl(chunkSize) { RollingSumHashFunction(chunkSize) }

val body = ByteArrayContent(payload)
val body = HttpBody.fromBytes(payload)
val hashes = hasher.calculateHashes(body)

assertContentEquals(fullHash, hashes.fullHash)
Expand Down

0 comments on commit aaa8846

Please sign in to comment.