-
Notifications
You must be signed in to change notification settings - Fork 559
/
index.ts
38 lines (34 loc) · 865 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import {
BuildHandler,
BuildHandlerArguments,
BuildMiddleware
} from "@aws-sdk/types";
import { HttpRequest } from "@aws-sdk/protocol-http";
export interface HeaderDefaultArgs {
[header: string]: string;
}
export function headerDefault(
headerBag: HeaderDefaultArgs
): BuildMiddleware<any, any> {
return (next: BuildHandler<any, any>) => {
return (args: BuildHandlerArguments<any>) => {
if (HttpRequest.isInstance(args.request)) {
const headers = { ...args.request.headers };
for (const name of Object.keys(headerBag)) {
if (!(name in headers)) {
headers[name] = headerBag[name];
}
}
return next({
...args,
request: {
...args.request,
headers
}
});
} else {
return next(args);
}
};
};
}