Skip to content

Commit a0f7f02

Browse files
authored
Correctly serialize/deserialize header lists (#2611)
1 parent dd724ec commit a0f7f02

File tree

6 files changed

+78
-4
lines changed

6 files changed

+78
-4
lines changed

build_tools/aws-sdk-code-generator/spec/protocols/input/rest-json.json

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,65 @@
110110
}
111111
]
112112
},
113+
{
114+
"description": "Header list of strings",
115+
"metadata": {
116+
"protocol": "rest-json",
117+
"apiVersion": "2014-01-01"
118+
},
119+
"shapes": {
120+
"InputShape": {
121+
"type": "structure",
122+
"members": {
123+
"ListOfStrings": {
124+
"shape": "StringList",
125+
"location": "header",
126+
"locationName": "x-amz-string-list"
127+
},
128+
"String": {
129+
"shape": "String",
130+
"location": "header",
131+
"locationName": "x-amz-string"
132+
}
133+
}
134+
},
135+
"StringList": {
136+
"type": "list",
137+
"member": {
138+
"shape": "String"
139+
}
140+
},
141+
"String": {
142+
"type": "string"
143+
}
144+
},
145+
"cases": [
146+
{
147+
"given": {
148+
"http": {
149+
"method": "GET",
150+
"requestUri": "/path"
151+
},
152+
"input": {
153+
"shape": "InputShape"
154+
},
155+
"name": "OperationName"
156+
},
157+
"params": {
158+
"ListOfStrings": ["value1", "value2"],
159+
"String": "singleValue"
160+
},
161+
"serialized": {
162+
"body": "",
163+
"uri": "/path",
164+
"headers": {
165+
"x-amz-string": "singleValue",
166+
"x-amz-string-list": "value1,value2"
167+
}
168+
}
169+
}
170+
]
171+
},
113172
{
114173
"description": "Querystring list of strings",
115174
"metadata": {

build_tools/aws-sdk-code-generator/spec/protocols/output/rest-json.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,11 @@
854854
},
855855
"ListEnums": {
856856
"shape": "EnumList"
857+
},
858+
"HeaderListEnums": {
859+
"shape": "EnumList",
860+
"location": "header",
861+
"locationName": "x-amz-enum-list"
857862
}
858863
}
859864
},
@@ -886,11 +891,12 @@
886891
"result": {
887892
"HeaderEnum": "baz",
888893
"FooEnum": "foo",
889-
"ListEnums": ["foo", "bar"]
894+
"ListEnums": ["foo", "bar"],
895+
"HeaderListEnums": ["foo", "bar"]
890896
},
891897
"response": {
892898
"status_code": 200,
893-
"headers": {"x-amz-enum": "baz"},
899+
"headers": {"x-amz-enum": "baz", "x-amz-enum-list": "foo,bar"},
894900
"body": "{\"FooEnum\": \"foo\", \"ListEnums\": [\"foo\", \"bar\"]}"
895901
}
896902
},

build_tools/aws-sdk-code-generator/spec/protocols_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def normalize_xml(xml)
191191
describe 'input' do
192192
each_test_case(self, files['input']) do |group, suite, test_case, name|
193193

194-
group.it "marshalls response data correctly" do
194+
group.it "marshals response data correctly" do
195195
client = client_for(suite, test_case, "Input_#{name}")
196196
ctx = nil
197197
client.handle(step: :send) do |context|

gems/aws-sdk-core/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Unreleased Changes
22
------------------
33

4+
* Issue - Correctly serialize/deserialize header lists.
5+
46
3.122.0 (2021-11-04)
57
------------------
68

gems/aws-sdk-core/lib/aws-sdk-core/rest/request/headers.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def apply_header_value(headers, ref, value)
3535
headers[ref.location_name] =
3636
case ref.shape
3737
when TimestampShape then timestamp(ref, value)
38+
when ListShape then list(ref, value)
3839
else value.to_s
3940
end
4041
end
@@ -49,6 +50,10 @@ def timestamp(ref, value)
4950
end
5051
end
5152

53+
def list(_ref, value)
54+
value.compact.join(",")
55+
end
56+
5257
def apply_header_map(headers, ref, values)
5358
prefix = ref.location_name || ''
5459
values.each_pair do |name, value|
@@ -57,7 +62,7 @@ def apply_header_map(headers, ref, values)
5762
end
5863

5964
# With complex headers value in json syntax,
60-
# base64 encodes value to aviod weird characters
65+
# base64 encodes value to avoid weird characters
6166
# causing potential issues in headers
6267
def apply_json_trait(value)
6368
Base64.strict_encode64(value)

gems/aws-sdk-core/lib/aws-sdk-core/rest/response/headers.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ def cast_value(ref, value)
4040
when IntegerShape then value.to_i
4141
when FloatShape then value.to_f
4242
when BooleanShape then value == 'true'
43+
when ListShape then
44+
value.split(",").map { |v| cast_value(ref.shape.member, v) }
4345
when TimestampShape
4446
if value =~ /^\d+(\.\d*)/
4547
Time.at(value.to_f)

0 commit comments

Comments
 (0)