@aws-amplify/core
Version:
Core category of aws-amplify
28 lines (26 loc) • 1.03 kB
JavaScript
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/**
* Middleware injects user agent string to specified header(default to 'x-amz-user-agent'),
* if the header is not set already.
*
* TODO: incorporate new user agent design
*/
const userAgentMiddlewareFactory = ({ userAgentHeader = 'x-amz-user-agent', userAgentValue = '', }) => next => {
return async function userAgentMiddleware(request) {
if (userAgentValue.trim().length === 0) {
const result = await next(request);
return result;
}
else {
const headerName = userAgentHeader.toLowerCase();
request.headers[headerName] = request.headers[headerName]
? `${request.headers[headerName]} ${userAgentValue}`
: userAgentValue;
const response = await next(request);
return response;
}
};
};
export { userAgentMiddlewareFactory };
//# sourceMappingURL=middleware.mjs.map