generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 175
Closed
Labels
completedThis item is complete and has been merged/shippedThis item is complete and has been merged/shippedevent-handlerThis item relates to the Event Handler UtilityThis item relates to the Event Handler Utilityfeature-requestThis item refers to a feature request for an existing or new utilityThis item refers to a feature request for an existing or new utility
Description
Use case
We should have a middleware that compresses response bodies to reduce payload size and improve performance. The middleware should support common compression algorithms with sensible defaults that can be overridden when initializing the middleware.
Solution/User Experience
The middleware will be applied like any other:
import { compress } from '@aws-lambda-powertools/event-handler/rest/middleware';
// use defaults
app.use(compress());
type options = {
encoding?: 'gzip' | 'deflate'
threshold?: number
}
// custom configuration
app.use(compress({
encoding: 'gzip',
threshold: 1024, // this will also be the default
}));
The middleware should:
- Only compress responses above the threshold size
- If
enocding
option is not present, infer fromAccept-Encoding
header with preference given togzip
- Avoid loading the whole request into memory, use streams instead
- Should we use the inbuilt Nodejs compression or CompressionStream. Explain your reasoning.
- Set appropriate Content-Encoding header
- Remove Content-Length header (since compressed size differs)
- Support gzip and deflate algorithms
- Check Accept-Encoding header to ensure client supports compression
- Skip compression for already compressed content types (images, videos, etc.)
Alternative solutions
Acknowledgment
- This feature request meets Powertools for AWS Lambda (TypeScript) Tenets
- Should this be considered in other Powertools for AWS Lambda languages? i.e. Python, Java, and .NET
Future readers
Please react with 👍 and your use case to help us understand customer demand.
Metadata
Metadata
Assignees
Labels
completedThis item is complete and has been merged/shippedThis item is complete and has been merged/shippedevent-handlerThis item relates to the Event Handler UtilityThis item relates to the Event Handler Utilityfeature-requestThis item refers to a feature request for an existing or new utilityThis item refers to a feature request for an existing or new utility
Type
Projects
Status
Shipped