Skip to content

Commit e6338ca

Browse files
authored
Allow all headers to be set to an empty value (#547)
1 parent e3a9df9 commit e6338ca

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/integration/HttpBindingProtocolGenerator.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -852,10 +852,8 @@ private void writeHttpBindingMember(
852852
});
853853
}
854854

855-
boolean allowZeroStrings = location != HttpBinding.Location.HEADER;
856-
857855
GoValueAccessUtils.writeIfNonZeroValueMember(context.getModel(), context.getSymbolProvider(), writer,
858-
memberShape, "v", allowZeroStrings, memberShape.isRequired(), (operand) -> {
856+
memberShape, "v", true, memberShape.isRequired(), (operand) -> {
859857
final String locationName = binding.getLocationName().isEmpty()
860858
? memberShape.getMemberName() : binding.getLocationName();
861859
switch (location) {
@@ -980,6 +978,13 @@ private void writeHeaderBinding(
980978
}
981979

982980
MemberShape collectionMemberShape = CodegenUtils.expectCollectionShape(targetShape).getMember();
981+
// On empty collection header will be set to an empty value
982+
writer.openBlock("if len($L) == 0 {", "}", operand, () -> {
983+
writeHttpBindingSetter(context, writer, collectionMemberShape, location, operand,
984+
(w, s) -> {
985+
w.writeInline("$L.AddHeader($L).String(\"\")", dest, locationName);
986+
});
987+
});
983988
writer.openBlock("for i := range $L {", "}", operand, () -> {
984989
// Only set non-empty non-nil header values
985990
String indexedOperand = operand + "[i]";

0 commit comments

Comments
 (0)