Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
): BuildMiddleware => next => async args => {
if (!HttpRequest.isInstance(args.request)) return next(args);
const { request } = args;
const { handlerProtocol = "" } = options.requestHandler.metadata || {};
//For H2 request, remove 'host' header and use ':authority' header instead
//reference: https://nodejs.org/dist/latest-v13.x/docs/api/errors.html#ERR_HTTP2_INVALID_CONNECTION_HEADERS
if (handlerProtocol.indexOf("h2") >= 0 && !request.headers[":authority"]) {
delete request.headers["host"];
request.headers[":authority"] = "";
//non-H2 request and 'host' header is not set, set the 'host' header to request's hostname.
} else if (!request.headers["host"]) {
request.headers["host"] = request.hostname;
}
return next(args);
};
): BuildHandler => (
args: BuildHandlerArguments
): Promise> => {
let { request } = args;
if (!HttpRequest.isInstance(request)) return next(args);
const { headers } = request;
if (!headers[userAgentHeader]) {
headers[userAgentHeader] = `${options.defaultUserAgent}`;
} else {
headers[userAgentHeader] += ` ${options.defaultUserAgent}`;
}
if (options.customUserAgent) {
headers[userAgentHeader] += ` ${options.customUserAgent}`;
}
return next({
...args,
request
});
};
}
return (args: BuildHandlerArguments) => {
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 {
async function(
args: FinalizeHandlerArguments<input>
): Promise> {
if (!HttpRequest.isInstance(args.request)) return next(args);
const signer =
typeof options.signer === "function"
? await options.signer()
: options.signer;
const output = await next({
...args,
request: await signer.sign(args.request, {
signingDate: new Date(Date.now() + options.systemClockOffset)
})
});
const { headers } = output.response as any;
const dateHeader = headers && (headers.date || headers.Date);
if (dateHeader) {
const serverTime = Date.parse(dateHeader);
if (isClockSkewed(serverTime, options.systemClockOffset)) {
): BuildHandler => async (
args: BuildHandlerArguments
): Promise> => {
let request = args.request;
if (HttpRequest.isInstance(request)) {
request.headers["x-amz-glacier-version"] = options.apiVersion;
}
return next({
...args,
request
});
};
}
): BuildHandler => async (
args: BuildHandlerArguments
): Promise> => {
let { request } = args;
if (
HttpRequest.isInstance(request) &&
request.body &&
options.runtime === "node"
) {
request.headers = {
...request.headers,
Expect: "100-continue"
};
}
return next({
...args,
request
});
};
}
): BuildHandler => async (
args: BuildHandlerArguments
): Promise> => {
const { Bucket: bucketName } = args.input;
let replaceBucketInPath = options.bucketEndpoint;
let request = args.request;
if (HttpRequest.isInstance(request)) {
if (options.bucketEndpoint) {
request.hostname = bucketName;
} else {
const { hostname, bucketEndpoint } = bucketHostname({
bucketName,
baseHostname: request.hostname,
accelerateEndpoint: options.useAccelerateEndpoint,
dualstackEndpoint: options.useDualstackEndpoint,
pathStyleEndpoint: options.forcePathStyle,
tlsCompatible: request.protocol === "https:"
});
request.hostname = hostname;
replaceBucketInPath = bucketEndpoint;
}
): BuildHandler => async (
args: BuildHandlerArguments
): Promise> => {
let { request } = args;
if (HttpRequest.isInstance(request)) {
request.headers = {
...request.headers,
accepts: "application/json"
};
}
return next({
...args,
request
});
};
}
): BuildHandler => async (
args: BuildHandlerArguments
): Promise> => {
let request = args.request;
if (HttpRequest.isInstance(request)) {
const { body, headers } = request;
if (
body &&
Object.keys(headers)
.map(str => str.toLowerCase())
.indexOf(CONTENT_LENGTH_HEADER) === -1
) {
const length = bodyLengthChecker(body);
if (length !== undefined) {
request.headers = {
...request.headers,
[CONTENT_LENGTH_HEADER]: String(length)
};
}
}
}
): BuildHandler => async (
args: BuildHandlerArguments
): Promise> => {
let { request } = args;
if (HttpRequest.isInstance(request)) {
const { body, headers } = request;
if (!hasHeader("Content-MD5", headers)) {
let digest: Promise;
if (
body === undefined ||
typeof body === "string" ||
ArrayBuffer.isView(body) ||
isArrayBuffer(body)
) {
const hash = new options.md5();
hash.update(body || "");
digest = hash.digest();
} else {
digest = options.streamHasher(options.md5, body);
}