Skip to content

Commit a07514f

Browse files
jeskewsrchase
authored andcommitted
Add a serialize middleware step to keep from having to check if the request exists in all build middleware
1 parent c02453d commit a07514f

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

packages/middleware-content-length/src/index.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ export function contentLengthMiddleware(
1414
): BuildHandler<any, Output, any> => async (
1515
args: BuildHandlerArguments<any, any>
1616
): Promise<Output> => {
17-
const {request} = args;
18-
if (!request) {
19-
throw new Error('Unable to determine request content-length due to missing request.');
20-
}
21-
17+
let request = {...args.request};
2218
const {body, headers} = request;
2319
if (
2420
body &&
@@ -28,7 +24,10 @@ export function contentLengthMiddleware(
2824
) {
2925
const length = bodyLengthCalculator(body);
3026
if (length !== undefined) {
31-
headers['Content-Length'] = String(length);
27+
request.headers = {
28+
...request.headers,
29+
'Content-Length': String(length),
30+
}
3231
}
3332
}
3433

packages/middleware-stack/src/index.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ import {
55
Middleware,
66
MiddlewareStack as IMiddlewareStack,
77
HandlerExecutionContext,
8+
Step,
89
} from '@aws/types';
910

10-
export type Step = 'initialize'|'build'|'finalize';
11-
1211
interface HandlerListEntry<
1312
Input extends object,
1413
Output extends object,
@@ -20,11 +19,17 @@ interface HandlerListEntry<
2019
tags?: {[tag: string]: any};
2120
}
2221

22+
export interface MiddlewareStack<
23+
Input extends object,
24+
Output extends object,
25+
Stream = Uint8Array
26+
> extends IMiddlewareStack<Input, Output, Stream> {}
27+
2328
export class MiddlewareStack<
2429
Input extends object,
2530
Output extends object,
2631
Stream = Uint8Array
27-
> implements IMiddlewareStack<Input, Output, Stream> {
32+
> {
2833
private readonly entries: Array<HandlerListEntry<Input, Output, Stream>> = [];
2934
private sorted: boolean = true;
3035

@@ -117,7 +122,8 @@ export class MiddlewareStack<
117122
}
118123

119124
const stepWeights = {
120-
initialize: 3,
125+
initialize: 4,
126+
serialize: 3,
121127
build: 2,
122128
finalize: 1,
123129
};

0 commit comments

Comments
 (0)