npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@epilot/large-response-middleware

v0.0.15

Published

Enables Lambdas to return responses larger than 6MB by offloading the content to S3 and returning a reference to the S3 file.

Downloads

102

Readme

Lambda Large Response Middleware

Enables Lambdas to return responses larger than 6MB by offloading the content to S3 and returning a reference to the S3 file.

Limitations

  • This implementation currently provides support for API Gateway with Lambda Proxy Integration only.
  • There are plans to extend this work as described here #issue-1

When a client can handle a Large Response, it must send a request with the HTTP Header Accept: application/large-response.vnd+json. The application/large-response.vnd+json is a custom MIME type indicating that the client agrees to receive a large response payload when necessary. The response body for the large-response.vnd+json MIME type is in the following format:

{
  "$payload_ref": "http://<s3 file reference link>"
}

If the client provides the large response MIME type, the Lambda will not log an error using Log.error. Instead, it will rewrite the original response with a reference to the offloaded large payload. Furthermore, the rewritten response will include the HTTP header Content-Type with the value application/large-response.vnd+json.

When the client doesn't provide the large response MIME type, and prefers to deal with the large response as a bad request instead of an HTTP 500, the client can send the Handle-Large-Response: true header. The Lambda will rewrite the original response with a custom message and HTTP status code 413 (Payload Too Large). This enables the client to detect a large response and handle it accordingly, by calling the API with a more strict filtering criteria.

If the client does not provide the large response MIME type, the Lambda will log an error with Log.error and rewrite the original response with a custom message (can be configured) and HTTP status code 413 (Payload Too Large).

Middleware Configuration:

Supported Parameters:

| Parameter | Type | Description | | --- | --- | --- | | thresholdWarn | number | Warning threshold level (percentage of sizeLimitInMB), e.g: 0.80 | | thresholdError | number | Error threshold level (percentage of sizeLimitInMB), e.g: 0.90 | | sizeLimitInMB | number | Maximum allowed size limit in MB, e.g 6 | | outputBucket | string | Identifier or name of the output S3 bucket | | customErrorMessage | string \| (event:APIGatewayProxyEventV2) => string | Custom error message to be returned when the response is too large and the client does not support large responses (no accept header) | | groupRequestsBy | function - mapper | Function to group requests, based on API Gateway event V2. Defaults to 'all' |

Example Usage:

withLargeResponseHandler({
  thresholdWarn: 0.85, // 85% of the limit = 5.1MB
  thresholdError: 0.9, // 90% of the limit = 5.4MB
  sizeLimitInMB: 6,
}),