@smithy/core 3.40.0 → 3.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/dist-cjs/submodules/protocols/index.js +600 -328
- package/dist-cjs/submodules/serde/index.browser.js +9 -4
- package/dist-cjs/submodules/serde/index.js +9 -4
- package/dist-cjs/submodules/serde/index.native.js +9 -4
- package/dist-es/submodules/protocols/HttpBindingNormalizedSchema.js +215 -0
- package/dist-es/submodules/protocols/HttpBindingProtocol.js +223 -195
- package/dist-es/submodules/protocols/HttpProtocol.js +22 -23
- package/dist-es/submodules/protocols/extended-encode-uri-component.js +3 -0
- package/dist-es/submodules/protocols/serde/FromStringShapeDeserializer.js +54 -47
- package/dist-es/submodules/protocols/serde/HttpInterceptingShapeDeserializer.js +23 -18
- package/dist-es/submodules/protocols/serde/HttpInterceptingShapeSerializer.js +12 -5
- package/dist-es/submodules/protocols/serde/ToStringShapeSerializer.js +33 -27
- package/dist-es/submodules/protocols/serde/determineTimestampFormat.js +5 -5
- package/dist-es/submodules/serde/quote-header.js +1 -1
- package/dist-es/submodules/serde/schema-serde-lib/schema-date-utils.js +4 -0
- package/dist-es/submodules/serde/split-header.js +4 -3
- package/dist-types/submodules/protocols/HttpBindingNormalizedSchema.d.ts +75 -0
- package/dist-types/submodules/protocols/HttpBindingProtocol.d.ts +11 -8
- package/dist-types/submodules/protocols/HttpProtocol.d.ts +2 -2
- package/dist-types/submodules/protocols/serde/FromStringShapeDeserializer.d.ts +2 -1
- package/dist-types/submodules/protocols/serde/HttpInterceptingShapeDeserializer.d.ts +4 -0
- package/dist-types/submodules/protocols/serde/HttpInterceptingShapeSerializer.d.ts +3 -0
- package/dist-types/submodules/protocols/serde/ToStringShapeSerializer.d.ts +2 -0
- package/dist-types/submodules/schema/schemas/NormalizedSchema.d.ts +1 -1
- package/dist-types/ts3.4/submodules/protocols/HttpBindingNormalizedSchema.d.ts +81 -0
- package/dist-types/ts3.4/submodules/protocols/HttpBindingProtocol.d.ts +11 -8
- package/dist-types/ts3.4/submodules/protocols/HttpProtocol.d.ts +1 -1
- package/dist-types/ts3.4/submodules/protocols/serde/FromStringShapeDeserializer.d.ts +2 -1
- package/dist-types/ts3.4/submodules/protocols/serde/HttpInterceptingShapeDeserializer.d.ts +4 -0
- package/dist-types/ts3.4/submodules/protocols/serde/HttpInterceptingShapeSerializer.d.ts +3 -0
- package/dist-types/ts3.4/submodules/protocols/serde/ToStringShapeSerializer.d.ts +2 -0
- package/dist-types/ts3.4/submodules/schema/schemas/NormalizedSchema.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,184 +1,220 @@
|
|
|
1
|
-
import { hasOwn } from "@smithy/core/transport";
|
|
2
|
-
import { NormalizedSchema, translateTraits } from "@smithy/core/schema";
|
|
1
|
+
import { hasOwn, HttpRequest } from "@smithy/core/transport";
|
|
3
2
|
import { sdkStreamMixin, splitEvery, splitHeader } from "@smithy/core/serde";
|
|
4
|
-
import {
|
|
3
|
+
import { getHttpOperationBindings, HttpBindingNormalizedSchema, } from "./HttpBindingNormalizedSchema";
|
|
5
4
|
import { HttpProtocol } from "./HttpProtocol";
|
|
6
5
|
import { collectBody } from "./collect-stream-body";
|
|
7
6
|
import { extendedEncodeURIComponent } from "./extended-encode-uri-component";
|
|
8
7
|
export class HttpBindingProtocol extends HttpProtocol {
|
|
9
8
|
async serializeRequest(operationSchema, _input, context) {
|
|
10
9
|
const input = _input && typeof _input === "object" ? _input : {};
|
|
11
|
-
const serializer = this.serializer;
|
|
12
10
|
const query = {};
|
|
13
11
|
const headers = {};
|
|
14
12
|
const endpoint = await context.endpoint();
|
|
15
|
-
const ns =
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
let payload;
|
|
20
|
-
const request = new HttpRequest({
|
|
21
|
-
protocol: "",
|
|
22
|
-
hostname: "",
|
|
23
|
-
port: undefined,
|
|
24
|
-
path: "",
|
|
25
|
-
fragment: undefined,
|
|
26
|
-
query: query,
|
|
27
|
-
headers: headers,
|
|
28
|
-
body: undefined,
|
|
29
|
-
});
|
|
13
|
+
const ns = HttpBindingNormalizedSchema.of(operationSchema?.input);
|
|
14
|
+
const bindings = ns.getHttpBindings().request;
|
|
15
|
+
const operation = getHttpOperationBindings(operationSchema);
|
|
16
|
+
const request = new HttpRequest({ query, headers });
|
|
30
17
|
if (endpoint) {
|
|
31
18
|
this.updateServiceEndpoint(request, endpoint);
|
|
32
|
-
this.setHostPrefix(request, operationSchema, input);
|
|
33
|
-
const
|
|
34
|
-
if (
|
|
35
|
-
request.method =
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
request.path = path;
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
request.path += path;
|
|
42
|
-
}
|
|
43
|
-
const traitSearchParams = new URLSearchParams(search ?? "");
|
|
44
|
-
for (const [key, value] of traitSearchParams) {
|
|
19
|
+
this.setHostPrefix(request, operationSchema, input, operation);
|
|
20
|
+
const [method, path, staticQuery] = operation;
|
|
21
|
+
if (method) {
|
|
22
|
+
request.method = method;
|
|
23
|
+
request.path = request.path === "/" ? path : request.path + path;
|
|
24
|
+
for (const [key, value] of staticQuery) {
|
|
45
25
|
query[key] = value;
|
|
46
26
|
}
|
|
47
27
|
}
|
|
48
28
|
}
|
|
49
|
-
|
|
50
|
-
|
|
29
|
+
request.query = query;
|
|
30
|
+
const eventStream = this.serializeHttpBindings(input, request, bindings, operation);
|
|
31
|
+
if (eventStream) {
|
|
32
|
+
request.body = await this.serializeEventStream({ eventStream, requestSchema: ns });
|
|
33
|
+
}
|
|
34
|
+
return request;
|
|
35
|
+
}
|
|
36
|
+
serializeHttpBindings(input, request, bindings, operation) {
|
|
37
|
+
const serializer = this.serializer;
|
|
38
|
+
const directSerializer = typeof serializer.writeCodec === "function"
|
|
39
|
+
? serializer
|
|
40
|
+
: undefined;
|
|
41
|
+
const query = request.query;
|
|
42
|
+
const headers = request.headers;
|
|
43
|
+
const bodySchema = bindings.syntheticBodySchema;
|
|
44
|
+
let hasBodyValue = false;
|
|
45
|
+
let payload;
|
|
46
|
+
let eventStream;
|
|
47
|
+
let labels;
|
|
48
|
+
const names = Object.getOwnPropertyNames(input);
|
|
49
|
+
const prototype = Object.getPrototypeOf(input);
|
|
50
|
+
const sparse = (prototype === Object.prototype || prototype === null) &&
|
|
51
|
+
!bindings.hasIdempotency &&
|
|
52
|
+
!bindings.hasPrefixHeaders &&
|
|
53
|
+
names.length * 2 < bindings.memberBindings.length;
|
|
54
|
+
const length = sparse ? names.length : bindings.memberBindings.length;
|
|
55
|
+
for (let i = 0; i < length; ++i) {
|
|
56
|
+
const binding = sparse
|
|
57
|
+
? hasOwn(bindings.byName, names[i])
|
|
58
|
+
? bindings.byName[names[i]]
|
|
59
|
+
: undefined
|
|
60
|
+
: bindings.memberBindings[i];
|
|
61
|
+
if (!binding) {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const value = binding[1];
|
|
65
|
+
const memberName = binding[0];
|
|
66
|
+
const memberNs = value[0];
|
|
67
|
+
const flags = value[1];
|
|
68
|
+
const collectionValue = value[2];
|
|
69
|
+
const location = binding[2];
|
|
70
|
+
const wireName = binding[3];
|
|
51
71
|
const inputMemberValue = input[memberName];
|
|
52
|
-
if (inputMemberValue == null && !
|
|
53
|
-
if (memberTraits.httpLabel) {
|
|
54
|
-
if (request.path.includes(`{${memberName}+}`) || request.path.includes(`{${memberName}}`)) {
|
|
55
|
-
throw new Error(`No value provided for input HTTP label: ${memberName}.`);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
72
|
+
if (inputMemberValue == null && !((flags >> 10) & 1)) {
|
|
58
73
|
continue;
|
|
59
74
|
}
|
|
60
|
-
if (
|
|
61
|
-
const
|
|
62
|
-
if (
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (input[memberName]) {
|
|
66
|
-
payload = await this.serializeEventStream({
|
|
67
|
-
eventStream: input[memberName],
|
|
68
|
-
requestSchema: ns,
|
|
69
|
-
});
|
|
70
|
-
}
|
|
75
|
+
if (location === 0b100_100) {
|
|
76
|
+
const stream = (flags >> 11) & 0b11;
|
|
77
|
+
if (stream) {
|
|
78
|
+
if (stream === 2) {
|
|
79
|
+
eventStream = inputMemberValue || undefined;
|
|
71
80
|
}
|
|
72
81
|
else {
|
|
73
82
|
payload = inputMemberValue;
|
|
74
83
|
}
|
|
75
84
|
}
|
|
76
85
|
else {
|
|
77
|
-
|
|
86
|
+
if (directSerializer) {
|
|
87
|
+
directSerializer.writeCodec(memberNs, inputMemberValue);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
serializer.write(memberNs, inputMemberValue);
|
|
91
|
+
}
|
|
78
92
|
payload = serializer.flush();
|
|
79
93
|
}
|
|
80
94
|
}
|
|
81
|
-
else if (
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
request.path = request.path.replace(`{${memberName}+}`, replacement.split("/").map(extendedEncodeURIComponent).join("/"));
|
|
95
|
+
else if (location === 0b100_001 || location === 0b100_110) {
|
|
96
|
+
const serialized = this.serializeHttpValue(value, inputMemberValue, location, directSerializer);
|
|
97
|
+
if (location === 0b100_001) {
|
|
98
|
+
(labels ??= Object.create(null))[memberName] = serialized;
|
|
86
99
|
}
|
|
87
|
-
else
|
|
88
|
-
|
|
100
|
+
else {
|
|
101
|
+
headers[wireName] = serialized;
|
|
89
102
|
}
|
|
90
103
|
}
|
|
91
|
-
else if (
|
|
92
|
-
serializer.write(memberNs, inputMemberValue);
|
|
93
|
-
headers[memberTraits.httpHeader.toLowerCase()] = String(serializer.flush());
|
|
94
|
-
}
|
|
95
|
-
else if (typeof memberTraits.httpPrefixHeaders === "string") {
|
|
104
|
+
else if (location === 0b100_111) {
|
|
96
105
|
for (const key in inputMemberValue) {
|
|
97
106
|
if (!hasOwn(inputMemberValue, key)) {
|
|
98
107
|
continue;
|
|
99
108
|
}
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
serializer.write([memberNs.getValueSchema(), { httpHeader: amalgam }], val);
|
|
103
|
-
headers[amalgam.toLowerCase()] = serializer.flush();
|
|
109
|
+
const amalgam = wireName + key;
|
|
110
|
+
headers[amalgam.toLowerCase()] = this.serializeHttpValue(collectionValue, inputMemberValue[key], 0b100_110, directSerializer, directSerializer ? collectionValue[0] : [collectionValue[0], { httpHeader: amalgam }]);
|
|
104
111
|
}
|
|
105
112
|
}
|
|
106
|
-
else if (
|
|
107
|
-
this.serializeQuery(
|
|
113
|
+
else if ((location & 0b111_110) === 0b100_010) {
|
|
114
|
+
this.serializeQuery(value, inputMemberValue, wireName, query, directSerializer);
|
|
108
115
|
}
|
|
109
116
|
else {
|
|
110
|
-
|
|
111
|
-
payloadMemberNames.push(memberName);
|
|
112
|
-
payloadMemberSchemas.push(memberNs);
|
|
117
|
+
hasBodyValue = true;
|
|
113
118
|
}
|
|
114
119
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
payloadMemberNames,
|
|
124
|
-
payloadMemberSchemas,
|
|
125
|
-
undefined,
|
|
126
|
-
];
|
|
127
|
-
if (requiredMembers) {
|
|
128
|
-
payloadSchema[6] = requiredMembers;
|
|
120
|
+
const operationPath = operation[1];
|
|
121
|
+
const pathSegments = operation[3];
|
|
122
|
+
if (operationPath && pathSegments && request.path.endsWith(operationPath)) {
|
|
123
|
+
request.path = request.path.slice(0, -operationPath.length) + this.serializePath(pathSegments, labels, bindings);
|
|
124
|
+
}
|
|
125
|
+
if (hasBodyValue && bodySchema) {
|
|
126
|
+
if (directSerializer) {
|
|
127
|
+
directSerializer.writeCodec(bodySchema, input);
|
|
129
128
|
}
|
|
130
129
|
else {
|
|
131
|
-
|
|
130
|
+
serializer.write(bodySchema, input);
|
|
132
131
|
}
|
|
133
|
-
serializer.write(payloadSchema, input);
|
|
134
132
|
payload = serializer.flush();
|
|
135
133
|
}
|
|
136
|
-
request.headers = headers;
|
|
137
|
-
request.query = query;
|
|
138
134
|
request.body = payload;
|
|
139
|
-
return
|
|
135
|
+
return eventStream;
|
|
140
136
|
}
|
|
141
|
-
serializeQuery(
|
|
142
|
-
const
|
|
143
|
-
const traits = ns.getMergedTraits();
|
|
144
|
-
if (
|
|
137
|
+
serializeQuery(value, data, wireName, query, directSerializer) {
|
|
138
|
+
const [ns, flags, collectionValue] = value;
|
|
139
|
+
const traits = directSerializer ? undefined : ns.getMergedTraits();
|
|
140
|
+
if (wireName === undefined) {
|
|
145
141
|
for (const key in data) {
|
|
146
|
-
if (!hasOwn(data, key)) {
|
|
142
|
+
if (!hasOwn(data, key) || key in query) {
|
|
147
143
|
continue;
|
|
148
144
|
}
|
|
149
|
-
if (!
|
|
150
|
-
|
|
151
|
-
const valueSchema = ns.getValueSchema();
|
|
152
|
-
Object.assign(valueSchema.getMergedTraits(), {
|
|
145
|
+
if (!directSerializer) {
|
|
146
|
+
Object.assign(collectionValue[0].getMergedTraits(), {
|
|
153
147
|
...traits,
|
|
154
148
|
httpQuery: key,
|
|
155
149
|
httpQueryParams: undefined,
|
|
156
150
|
});
|
|
157
|
-
this.serializeQuery(valueSchema, val, query);
|
|
158
151
|
}
|
|
152
|
+
this.serializeQuery(collectionValue, data[key], key, query, directSerializer);
|
|
159
153
|
}
|
|
160
154
|
return;
|
|
161
155
|
}
|
|
162
|
-
if (
|
|
163
|
-
const sparse = !!ns.getMergedTraits().sparse;
|
|
156
|
+
if ((flags & 0b1100_0000) === 0b0100_0000) {
|
|
164
157
|
const buffer = [];
|
|
165
158
|
for (const item of data) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
buffer.push(serializable);
|
|
159
|
+
const serialized = this.serializeHttpValue(collectionValue, item, 0b100_010, directSerializer, directSerializer ? collectionValue[0] : [collectionValue[0], traits]);
|
|
160
|
+
if ((flags >> 13) & 1 || serialized !== undefined) {
|
|
161
|
+
buffer.push(serialized);
|
|
170
162
|
}
|
|
171
163
|
}
|
|
172
|
-
query[
|
|
164
|
+
query[wireName] = buffer;
|
|
173
165
|
}
|
|
174
166
|
else {
|
|
175
|
-
|
|
176
|
-
query[traits.httpQuery] = serializer.flush();
|
|
167
|
+
query[wireName] = this.serializeHttpValue(value, data, 0b100_010, directSerializer, directSerializer ? ns : [ns, traits]);
|
|
177
168
|
}
|
|
178
169
|
}
|
|
170
|
+
serializeHttpValue(value, data, location, directSerializer, schema = value[0]) {
|
|
171
|
+
const flags = value[1];
|
|
172
|
+
const type = flags & 0xff;
|
|
173
|
+
if (directSerializer &&
|
|
174
|
+
!(flags & 0x700) &&
|
|
175
|
+
(type <= 2 ||
|
|
176
|
+
type === 17 ||
|
|
177
|
+
type === 19)) {
|
|
178
|
+
return String(data);
|
|
179
|
+
}
|
|
180
|
+
if (directSerializer) {
|
|
181
|
+
directSerializer.writeHttpBinding(value, data, location);
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
this.serializer.write(schema, data);
|
|
185
|
+
}
|
|
186
|
+
return this.serializer.flush();
|
|
187
|
+
}
|
|
188
|
+
serializePath(segments, labels, bindings) {
|
|
189
|
+
let path = "";
|
|
190
|
+
for (const [value, kind] of segments) {
|
|
191
|
+
if (kind === 0) {
|
|
192
|
+
path += value;
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
const replacement = labels?.[value];
|
|
196
|
+
if (replacement === undefined) {
|
|
197
|
+
if (hasOwn(bindings.byName, value) && bindings.byName[value][2] === 0b100_001) {
|
|
198
|
+
throw new Error(`No value provided for input HTTP label: ${value}.`);
|
|
199
|
+
}
|
|
200
|
+
path += `{${value}${kind === 2 ? "+" : ""}}`;
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
path +=
|
|
204
|
+
kind === 2
|
|
205
|
+
? replacement.split("/").map(extendedEncodeURIComponent).join("/")
|
|
206
|
+
: extendedEncodeURIComponent(replacement);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return path;
|
|
210
|
+
}
|
|
179
211
|
async deserializeResponse(operationSchema, context, response) {
|
|
180
212
|
const deserializer = this.deserializer;
|
|
181
|
-
const
|
|
213
|
+
const directDeserializer = typeof deserializer.readCodec === "function"
|
|
214
|
+
? deserializer
|
|
215
|
+
: undefined;
|
|
216
|
+
const ns = HttpBindingNormalizedSchema.of(operationSchema.output);
|
|
217
|
+
const responseBindings = ns.getHttpBindings().response;
|
|
182
218
|
const dataObject = {};
|
|
183
219
|
if (response.statusCode >= 300) {
|
|
184
220
|
const bytes = await collectBody(response.body, context);
|
|
@@ -188,19 +224,13 @@ export class HttpBindingProtocol extends HttpProtocol {
|
|
|
188
224
|
await this.handleError(operationSchema, context, response, dataObject, this.deserializeMetadata(response));
|
|
189
225
|
throw new Error("@smithy/core/protocols - HTTP Protocol error handler failed to throw.");
|
|
190
226
|
}
|
|
191
|
-
for (const header in response.headers) {
|
|
192
|
-
if (!hasOwn(response.headers, header)) {
|
|
193
|
-
continue;
|
|
194
|
-
}
|
|
195
|
-
const value = response.headers[header];
|
|
196
|
-
delete response.headers[header];
|
|
197
|
-
response.headers[header.toLowerCase()] = value;
|
|
198
|
-
}
|
|
199
227
|
const nonHttpBindingMembers = await this.deserializeHttpMessage(ns, context, response, dataObject);
|
|
200
228
|
if (nonHttpBindingMembers.length) {
|
|
201
229
|
const bytes = await collectBody(response.body, context);
|
|
202
230
|
if (bytes.byteLength > 0) {
|
|
203
|
-
const dataFromBody = await
|
|
231
|
+
const dataFromBody = await (directDeserializer
|
|
232
|
+
? directDeserializer.readCodec(responseBindings.syntheticBodySchema, bytes)
|
|
233
|
+
: deserializer.read(responseBindings.syntheticBodySchema, bytes));
|
|
204
234
|
for (const member of nonHttpBindingMembers) {
|
|
205
235
|
if (dataFromBody[member] != null) {
|
|
206
236
|
dataObject[member] = dataFromBody[member];
|
|
@@ -208,96 +238,94 @@ export class HttpBindingProtocol extends HttpProtocol {
|
|
|
208
238
|
}
|
|
209
239
|
}
|
|
210
240
|
}
|
|
211
|
-
else if (
|
|
241
|
+
else if (!responseBindings.bindings.payload) {
|
|
212
242
|
await collectBody(response.body, context);
|
|
213
243
|
}
|
|
214
244
|
dataObject.$metadata = this.deserializeMetadata(response);
|
|
215
245
|
return dataObject;
|
|
216
246
|
}
|
|
217
247
|
async deserializeHttpMessage(schema, context, response, arg4, arg5) {
|
|
218
|
-
|
|
219
|
-
if (arg4 instanceof Set) {
|
|
220
|
-
dataObject = arg5;
|
|
221
|
-
}
|
|
222
|
-
else {
|
|
223
|
-
dataObject = arg4;
|
|
224
|
-
}
|
|
225
|
-
let discardResponseBody = true;
|
|
248
|
+
const dataObject = arg4 instanceof Set ? arg5 : arg4;
|
|
226
249
|
const deserializer = this.deserializer;
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
dataObject[memberName] = sdkStreamMixin(response.body);
|
|
244
|
-
}
|
|
250
|
+
const directDeserializer = typeof deserializer.readCodec === "function"
|
|
251
|
+
? deserializer
|
|
252
|
+
: undefined;
|
|
253
|
+
const ns = HttpBindingNormalizedSchema.of(schema);
|
|
254
|
+
const { bodyMemberNames, bindings: { payload, statusCode, headers: responseHeaders, prefixHeaders }, } = ns.getHttpBindings().response;
|
|
255
|
+
const headers = response.headers;
|
|
256
|
+
if (payload) {
|
|
257
|
+
const [memberName, value] = payload;
|
|
258
|
+
const [memberSchema, flags] = value;
|
|
259
|
+
const stream = (flags >> 11) & 0b11;
|
|
260
|
+
if (stream) {
|
|
261
|
+
if (stream === 2) {
|
|
262
|
+
dataObject[memberName] = await this.deserializeEventStream({
|
|
263
|
+
response,
|
|
264
|
+
responseSchema: ns,
|
|
265
|
+
});
|
|
245
266
|
}
|
|
246
|
-
else
|
|
247
|
-
|
|
248
|
-
if (bytes.byteLength > 0) {
|
|
249
|
-
dataObject[memberName] = await deserializer.read(memberSchema, bytes);
|
|
250
|
-
}
|
|
267
|
+
else {
|
|
268
|
+
dataObject[memberName] = sdkStreamMixin(response.body);
|
|
251
269
|
}
|
|
252
270
|
}
|
|
253
|
-
else if (
|
|
254
|
-
const
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
headerListValueSchema.getMergedTraits().httpHeader = key;
|
|
260
|
-
let sections;
|
|
261
|
-
if (headerListValueSchema.isTimestampSchema() &&
|
|
262
|
-
headerListValueSchema.getSchema() === 4) {
|
|
263
|
-
sections = splitEvery(value, ",", 2);
|
|
264
|
-
}
|
|
265
|
-
else {
|
|
266
|
-
sections = splitHeader(value);
|
|
267
|
-
}
|
|
268
|
-
const list = [];
|
|
269
|
-
for (const section of sections) {
|
|
270
|
-
list.push(await deserializer.read(headerListValueSchema, section.trim()));
|
|
271
|
-
}
|
|
272
|
-
dataObject[memberName] = list;
|
|
273
|
-
}
|
|
274
|
-
else {
|
|
275
|
-
dataObject[memberName] = await deserializer.read(memberSchema, value);
|
|
276
|
-
}
|
|
271
|
+
else if (response.body) {
|
|
272
|
+
const bytes = await collectBody(response.body, context);
|
|
273
|
+
if (bytes.byteLength > 0) {
|
|
274
|
+
dataObject[memberName] = await (directDeserializer
|
|
275
|
+
? directDeserializer.readPayload(value, bytes)
|
|
276
|
+
: deserializer.read(memberSchema, bytes));
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
dataObject[memberName][header.slice(memberTraits.httpPrefixHeaders.length)] = await deserializer.read(valueSchema, value);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
279
|
+
}
|
|
280
|
+
for (const header in headers) {
|
|
281
|
+
if (!hasOwn(headers, header)) {
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
const lower = header.toLowerCase();
|
|
285
|
+
const headerValue = headers[header];
|
|
286
|
+
if (lower !== header) {
|
|
287
|
+
delete headers[header];
|
|
288
|
+
headers[lower] = headerValue;
|
|
292
289
|
}
|
|
293
|
-
|
|
294
|
-
|
|
290
|
+
const binding = hasOwn(responseHeaders, lower) ? responseHeaders[lower] : undefined;
|
|
291
|
+
if (!binding) {
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
const [memberName, [memberSchema, flags, collectionValue], , wireName] = binding;
|
|
295
|
+
if (collectionValue) {
|
|
296
|
+
const sections = (flags >> 16) & 1 ? splitEvery(headerValue, ",", 2) : splitHeader(headerValue);
|
|
297
|
+
const list = [];
|
|
298
|
+
for (const section of sections) {
|
|
299
|
+
list.push(directDeserializer
|
|
300
|
+
? directDeserializer.readHttpBinding(collectionValue, section.trim(), 0b100_110)
|
|
301
|
+
: await deserializer.read([collectionValue[0], { httpHeader: wireName }], section.trim()));
|
|
302
|
+
}
|
|
303
|
+
dataObject[memberName] = list;
|
|
295
304
|
}
|
|
296
305
|
else {
|
|
297
|
-
|
|
306
|
+
dataObject[memberName] = directDeserializer
|
|
307
|
+
? directDeserializer.readHttpBinding(binding[1], headerValue, 0b100_110)
|
|
308
|
+
: await deserializer.read(memberSchema, headerValue);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
for (const [memberName, [, , collectionValue], , wireName] of prefixHeaders) {
|
|
312
|
+
dataObject[memberName] = {};
|
|
313
|
+
for (const header in headers) {
|
|
314
|
+
if (!hasOwn(headers, header)) {
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
if (!header.startsWith(wireName)) {
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
const headerValue = headers[header];
|
|
321
|
+
dataObject[memberName][header.slice(wireName.length)] = directDeserializer
|
|
322
|
+
? directDeserializer.readHttpBinding(collectionValue, headerValue, 0b100_110)
|
|
323
|
+
: await deserializer.read([collectionValue[0], { httpHeader: header }], headerValue);
|
|
298
324
|
}
|
|
299
325
|
}
|
|
300
|
-
|
|
301
|
-
|
|
326
|
+
if (statusCode) {
|
|
327
|
+
dataObject[statusCode[0]] = response.statusCode;
|
|
328
|
+
}
|
|
329
|
+
return bodyMemberNames;
|
|
302
330
|
}
|
|
303
331
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { hasOwn } from "@smithy/core/transport";
|
|
2
|
-
import {
|
|
3
|
-
import { HttpRequest, HttpResponse, isValidHostname } from "@smithy/core/transport";
|
|
1
|
+
import { hasOwn, HttpRequest, HttpResponse, isValidHostname } from "@smithy/core/transport";
|
|
2
|
+
import { TypeRegistry } from "@smithy/core/schema";
|
|
4
3
|
import { SerdeContext } from "./SerdeContext";
|
|
4
|
+
import { getHttpOperationBindings, HttpBindingNormalizedSchema } from "./HttpBindingNormalizedSchema";
|
|
5
5
|
export class HttpProtocol extends SerdeContext {
|
|
6
6
|
options;
|
|
7
7
|
compositeErrorRegistry;
|
|
@@ -71,30 +71,29 @@ export class HttpProtocol extends SerdeContext {
|
|
|
71
71
|
return request;
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
-
setHostPrefix(request, operationSchema, input) {
|
|
74
|
+
setHostPrefix(request, operationSchema, input, operation = getHttpOperationBindings(operationSchema)) {
|
|
75
75
|
if (this.serdeContext?.disableHostPrefix) {
|
|
76
76
|
return;
|
|
77
77
|
}
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const replacement = input[name];
|
|
88
|
-
if (typeof replacement !== "string") {
|
|
89
|
-
throw new Error(`@smithy/core/schema - ${name} in input must be a string as hostLabel.`);
|
|
90
|
-
}
|
|
91
|
-
hostPrefix = hostPrefix.replace(`{${name}}`, replacement);
|
|
92
|
-
}
|
|
93
|
-
request.hostname = hostPrefix + request.hostname;
|
|
94
|
-
if (!isValidHostname(request.hostname)) {
|
|
95
|
-
throw new Error(`[${request.hostname}] is not a valid hostname.`);
|
|
96
|
-
}
|
|
78
|
+
const hostPrefix = operation[4];
|
|
79
|
+
if (typeof hostPrefix !== "string") {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
let resolvedHostPrefix = hostPrefix;
|
|
83
|
+
for (const [name, [, flags]] of HttpBindingNormalizedSchema.of(operationSchema.input).getHttpBindings().request
|
|
84
|
+
.memberBindings) {
|
|
85
|
+
if (!((flags >> 17) & 1)) {
|
|
86
|
+
continue;
|
|
97
87
|
}
|
|
88
|
+
const replacement = input[name];
|
|
89
|
+
if (typeof replacement !== "string") {
|
|
90
|
+
throw new Error(`@smithy/core/schema - ${name} in input must be a string as hostLabel.`);
|
|
91
|
+
}
|
|
92
|
+
resolvedHostPrefix = resolvedHostPrefix.replace(`{${name}}`, replacement);
|
|
93
|
+
}
|
|
94
|
+
request.hostname = resolvedHostPrefix + request.hostname;
|
|
95
|
+
if (!isValidHostname(request.hostname)) {
|
|
96
|
+
throw new Error(`[${request.hostname}] is not a valid hostname.`);
|
|
98
97
|
}
|
|
99
98
|
}
|
|
100
99
|
deserializeMetadata(output) {
|