Repository navigation
Conversation
|
Thanks for testing it! I pushed a change that does that:
Headers are not measured, so a response with more than about 16 KB of headers could still go over; I can count them exactly too if you prefer that over a constant. |
|
I don't think HTTP status code 413 makes sense because that is supposed to be for a request being too large not a response. That means it was a client error for sending something too large. In this case it is a server error with the server, in this case Lambda, creating an invalid response. I understand your desire to differentiate an error that is due to a response too large but from the HTTP spec point of view 502 fits. In this case API Gateway or ALB received an invalid response from the upstream server which is the Lambda function. |
|
Agreed, the function is the one producing the invalid response, so 502 is the right code. I switched both |
|
Since we are throwing a 502 isn't that what API Gateway and ALB do by default? So in that I don't think we should do anything in this library. Sorry it sounds like we should have done better research on the issue along time ago and closed as work as expected. |
|
That makes sense. With 502 the client sees the same status API Gateway and ALB already return, and RuntimeSupport already surfaces the Runtime API's 413 as an error in the logs, so the only thing this PR would add is a hook to customize the response in |
Issue #, if available: #1815
Description of changes:
Following the approach suggested in the issue: when the marshalled response body is larger than the 6 MB Lambda payload limit,
APIGatewayProxyFunctionandAPIGatewayHttpApiV2ProxyFunctionnow return a 502 (and log an error) instead of the invocation failing with an opaque error. The check runs inMarshallResponsebeforePostMarshallResponseFeature, so users can still customize the 502 response.Utilities.IsResponseBodyTooLarge: the body is measured as it is written into the response JSON (escaped withJavaScriptEncoder.UnsafeRelaxedJsonEscaping, counted in UTF-8 bytes), against 6 MB minus a fixed 16 KBResponseEnvelopeHeadroomfor the status code, headers and property names.Amazon.Lambda.AspNetCoreServer(patch).LargeResponseControllerin TestWebApp. All 239 tests inAmazon.Lambda.AspNetCoreServer.Testpass on net8.0 and net10.0.Notes for review:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.