Skip to content

Commit 1ff5070

Browse files
committed
Merge remote-tracking branch 'origin/main' into release
2 parents d9b8154 + 1807e54 commit 1ff5070

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/rendering/protocol/HttpBindingProtocolGenerator.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,9 @@ abstract class HttpBindingProtocolGenerator : ProtocolGenerator {
274274
}
275275

276276
resolver.determineRequestContentType(op)?.let { contentType ->
277-
writer.write("builder.headers.setMissing(\"Content-Type\", #S)", contentType)
277+
writer.withBlock("if (builder.body !is HttpBody.Empty) {", "}") {
278+
write("builder.headers.setMissing(\"Content-Type\", #S)", contentType)
279+
}
278280
}
279281
}
280282

smithy-kotlin-codegen/src/test/kotlin/software/amazon/smithy/kotlin/codegen/IdempotentTokenGeneratorTest.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ class IdempotentTokenGeneratorTest {
4242
4343
val payload = serializeAllocateWidgetOperationBody(context, input)
4444
builder.body = ByteArrayContent(payload)
45-
builder.headers.setMissing("Content-Type", "application/json")
45+
if (builder.body !is HttpBody.Empty) {
46+
builder.headers.setMissing("Content-Type", "application/json")
47+
}
4648
return builder
4749
}
4850
}

smithy-kotlin-codegen/src/test/kotlin/software/amazon/smithy/kotlin/codegen/rendering/protocol/HttpBindingProtocolGeneratorTest.kt

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ internal class SmokeTestOperationSerializer: HttpSerialize<SmokeTestRequest> {
7272
7373
val payload = serializeSmokeTestOperationBody(context, input)
7474
builder.body = ByteArrayContent(payload)
75-
builder.headers.setMissing("Content-Type", "application/json")
75+
if (builder.body !is HttpBody.Empty) {
76+
builder.headers.setMissing("Content-Type", "application/json")
77+
}
7678
return builder
7779
}
7880
}
@@ -99,7 +101,9 @@ internal class ExplicitStringOperationSerializer: HttpSerialize<ExplicitStringRe
99101
if (input.payload1 != null) {
100102
builder.body = ByteArrayContent(input.payload1.encodeToByteArray())
101103
}
102-
builder.headers.setMissing("Content-Type", "text/plain")
104+
if (builder.body !is HttpBody.Empty) {
105+
builder.headers.setMissing("Content-Type", "text/plain")
106+
}
103107
return builder
104108
}
105109
}
@@ -124,7 +128,9 @@ internal class ExplicitBlobOperationSerializer: HttpSerialize<ExplicitBlobReques
124128
if (input.payload1 != null) {
125129
builder.body = ByteArrayContent(input.payload1)
126130
}
127-
builder.headers.setMissing("Content-Type", "application/octet-stream")
131+
if (builder.body !is HttpBody.Empty) {
132+
builder.headers.setMissing("Content-Type", "application/octet-stream")
133+
}
128134
return builder
129135
}
130136
}
@@ -149,7 +155,9 @@ internal class ExplicitBlobStreamOperationSerializer: HttpSerialize<ExplicitBlob
149155
if (input.payload1 != null) {
150156
builder.body = input.payload1.toHttpBody() ?: HttpBody.Empty
151157
}
152-
builder.headers.setMissing("Content-Type", "application/octet-stream")
158+
if (builder.body !is HttpBody.Empty) {
159+
builder.headers.setMissing("Content-Type", "application/octet-stream")
160+
}
153161
return builder
154162
}
155163
}
@@ -175,7 +183,9 @@ internal class ExplicitStructOperationSerializer: HttpSerialize<ExplicitStructRe
175183
val payload = serializeNested2Payload(input.payload1)
176184
builder.body = ByteArrayContent(payload)
177185
}
178-
builder.headers.setMissing("Content-Type", "application/json")
186+
if (builder.body !is HttpBody.Empty) {
187+
builder.headers.setMissing("Content-Type", "application/json")
188+
}
179189
return builder
180190
}
181191
}
@@ -203,7 +213,9 @@ internal class EnumInputOperationSerializer: HttpSerialize<EnumInputRequest> {
203213
204214
val payload = serializeEnumInputOperationBody(context, input)
205215
builder.body = ByteArrayContent(payload)
206-
builder.headers.setMissing("Content-Type", "application/json")
216+
if (builder.body !is HttpBody.Empty) {
217+
builder.headers.setMissing("Content-Type", "application/json")
218+
}
207219
return builder
208220
}
209221
}
@@ -243,7 +255,9 @@ internal class TimestampInputOperationSerializer: HttpSerialize<TimestampInputRe
243255
244256
val payload = serializeTimestampInputOperationBody(context, input)
245257
builder.body = ByteArrayContent(payload)
246-
builder.headers.setMissing("Content-Type", "application/json")
258+
if (builder.body !is HttpBody.Empty) {
259+
builder.headers.setMissing("Content-Type", "application/json")
260+
}
247261
return builder
248262
}
249263
}
@@ -274,7 +288,9 @@ internal class BlobInputOperationSerializer: HttpSerialize<BlobInputRequest> {
274288
275289
val payload = serializeBlobInputOperationBody(context, input)
276290
builder.body = ByteArrayContent(payload)
277-
builder.headers.setMissing("Content-Type", "application/json")
291+
if (builder.body !is HttpBody.Empty) {
292+
builder.headers.setMissing("Content-Type", "application/json")
293+
}
278294
return builder
279295
}
280296
}

0 commit comments

Comments
 (0)