Skip to content

Commit 2144988

Browse files
authored
Merge pull request #4898 from aws/fix-restxml-emptyheaderlist
fix header serialization of empty enum lists in restxml
2 parents 8edbac8 + 65bdb4e commit 2144988

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

CHANGELOG_PENDING.md

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
### SDK Enhancements
44

55
### SDK Bugs
6+
* `private/protocol`: Fix header serialization of empty enum lists in restxml.
7+
* Header was serialized as the empty string if list was nil/empty.

private/protocol/rest/build.go

+4
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,10 @@ func convertType(v reflect.Value, tag reflect.StructTag) (str string, err error)
287287
if tag.Get("location") != "header" || tag.Get("enum") == "" {
288288
return "", fmt.Errorf("%T is only supported with location header and enum shapes", value)
289289
}
290+
if len(value) == 0 {
291+
return "", errValueNotSet
292+
}
293+
290294
buff := &bytes.Buffer{}
291295
for i, sv := range value {
292296
if sv == nil || len(*sv) == 0 {

private/protocol/rest/build_test.go

+22
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,28 @@ func TestListOfEnums(t *testing.T) {
147147
"X-Amz-Test-Header": {`"f,o,o","\"bar\""`},
148148
},
149149
},
150+
{
151+
Input: func() interface{} {
152+
type v struct {
153+
List []*string `type:"list" location:"header" locationName:"x-amz-test-header" enum:"FooBar"`
154+
}
155+
return &v{
156+
List: nil,
157+
}
158+
}(),
159+
Expected: http.Header{},
160+
},
161+
{
162+
Input: func() interface{} {
163+
type v struct {
164+
List []*string `type:"list" location:"header" locationName:"x-amz-test-header" enum:"FooBar"`
165+
}
166+
return &v{
167+
List: []*string{},
168+
}
169+
}(),
170+
Expected: http.Header{},
171+
},
150172
}
151173

152174
for i, tt := range cases {

0 commit comments

Comments
 (0)