Skip to content

Commit

Permalink
Allow all headers to be set to an empty value (#547)
Browse files Browse the repository at this point in the history
  • Loading branch information
Madrigal authored Oct 8, 2024
1 parent e3a9df9 commit e6338ca
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -852,10 +852,8 @@ private void writeHttpBindingMember(
});
}

boolean allowZeroStrings = location != HttpBinding.Location.HEADER;

GoValueAccessUtils.writeIfNonZeroValueMember(context.getModel(), context.getSymbolProvider(), writer,
memberShape, "v", allowZeroStrings, memberShape.isRequired(), (operand) -> {
memberShape, "v", true, memberShape.isRequired(), (operand) -> {
final String locationName = binding.getLocationName().isEmpty()
? memberShape.getMemberName() : binding.getLocationName();
switch (location) {
Expand Down Expand Up @@ -980,6 +978,13 @@ private void writeHeaderBinding(
}

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

0 comments on commit e6338ca

Please sign in to comment.