What is @aws-sdk/middleware-header-default?
@aws-sdk/middleware-header-default is a middleware package for the AWS SDK for JavaScript. It allows you to set default headers for your AWS service requests, ensuring that certain headers are always included in your requests without having to manually add them each time.
Setting Default Headers
This feature allows you to set default headers for all requests made with a specific AWS service client. In this example, a custom header 'x-custom-header' with the value 'my-custom-value' is added to all requests made with the S3 client.
const { HeaderDefaultMiddleware } = require('@aws-sdk/middleware-header-default');
const { S3Client } = require('@aws-sdk/client-s3');
const client = new S3Client({
region: 'us-west-2',
middlewareStack: (stack) => {
stack.add(HeaderDefaultMiddleware({
'x-custom-header': 'my-custom-value'
}), {
step: 'build',
priority: 'high'
});
}
});
// Now all requests made with this client will include the 'x-custom-header' header.