Skip to content

Commit f5a22c5

Browse files
authored
fix: only set Content-Type when appropriate (#570)
1 parent 078b70a commit f5a22c5

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/RestJson1.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,14 @@ class RestJson1 : JsonHttpBindingProtocolGenerator() {
5151
// explicit payload member as the sole payload
5252
val memberName = httpPayload.member.defaultName()
5353
val target = ctx.model.expectShape(httpPayload.member.target)
54-
if (target is StructureShape) {
55-
writer.withBlock("if (input.#L == null) {", "}", memberName) {
54+
writer.withBlock("if (input.#L == null) {", "}", memberName) {
55+
if (target is StructureShape) {
5656
addImport(RuntimeTypes.Http.ByteArrayContent)
5757
write("builder.body = #T(#S.encodeToByteArray())", RuntimeTypes.Http.ByteArrayContent, "{}")
5858
}
59+
// Content-Type still needs to be set for non-structured payloads
60+
// https://github.com/awslabs/smithy/blob/main/smithy-aws-protocol-tests/model/restJson1/http-content-type.smithy#L174
61+
write("builder.headers.setMissing(\"Content-Type\", #S)", resolver.determineRequestContentType(op))
5962
}
6063
}
6164
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ sdkVersion=0.14.3-SNAPSHOT
1212
smithyVersion=1.17.0
1313
smithyGradleVersion=0.5.3
1414
# smithy-kotlin codegen and runtime are versioned together
15-
smithyKotlinVersion=0.8.2
15+
smithyKotlinVersion=0.8.3-SNAPSHOT
1616

1717
# kotlin
1818
kotlinVersion=1.6.10

services/s3/model/s3-tests.smithy

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,38 @@ apply PutObject @httpRequestTests([
6363
}
6464
}
6565
])
66+
67+
apply CreateBucket @httpRequestTests([
68+
{
69+
id: "CreateBucketNoBody",
70+
documentation: "Validates https://github.com/awslabs/aws-sdk-kotlin/issues/567 (empty body)",
71+
protocol: "aws.protocols#restXml",
72+
method: "PUT",
73+
uri: "/mybucket",
74+
host: "s3.us-west-2.amazonaws.com",
75+
body: "",
76+
forbidHeaders: ["Content-Type", "Content-Length"],
77+
params: {
78+
Bucket: "mybucket",
79+
}
80+
},
81+
{
82+
id: "CreateBucketWithBody",
83+
documentation: "This test case validates https://github.com/awslabs/aws-sdk-kotlin/issues/567 (non-empty body)",
84+
protocol: "aws.protocols#restXml",
85+
method: "PUT",
86+
uri: "/mybucket",
87+
host: "s3.us-west-2.amazonaws.com",
88+
body: "<CreateBucketConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><LocationConstraint>us-east-2</LocationConstraint></CreateBucketConfiguration>",
89+
headers: {
90+
"Content-Type": "application/xml",
91+
"Content-Length": "153"
92+
},
93+
params: {
94+
Bucket: "mybucket",
95+
CreateBucketConfiguration: {
96+
LocationConstraint: "us-east-2"
97+
}
98+
}
99+
}
100+
])

0 commit comments

Comments
 (0)