micronaut-aws icon indicating copy to clipboard operation
micronaut-aws copied to clipboard

When implementing Controllers using lambdas, handle "Accepted-Encoding" and "Encoded-Content" headers transparently to decide if lambda response should be binary.

Open dniel opened this issue 7 months ago • 2 comments

Feature description

When using the API-Gateway to integrate with a AWS Lambda its easy to reach the 6mb limit of lambda payload response if returning plain text response. A http client should be able to send Accepted-Encoding to gzip and expect the response to be gzipped and the Encoded-Content header in the result to be set to gzip.

Implementing a AWS Lambda using @Controller and annotations such as @Get should handle Accepted-Encoding header to decide it should gzip the response and set isBase64Encoded=true in response transparently for the user just like when handling request when running as a netty container.

Example

@Controller
class RestApiController(){

  @Get("/something")
    fun getSomething(): HttpResponse{
       val giganticResponse = ... // something 10 mb from the database
      
       // should be gzipped to avoid aws limit to 6mb payload response.
       // especially if incoming header from API-Gateway Accept-Content has "gzip"
       return HttpResponse.ok(giganticResponse)
    }
}

dniel avatar Nov 15 '23 15:11 dniel