-
-
Notifications
You must be signed in to change notification settings - Fork 376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
util.normalizeHttpResponse to assume statusCode=200 when missing #874
Comments
As a possible workaround, if anyone else encounters the same issue, we are using a micro-middleware, which makes this behavior explicit. Full source:
Usage is then straightforward. For the
or for a different one (this use case would not be covered by the proposal above):
|
Thanks for the detailed report. Option A:
I would consider this to be safe and inline with AWS docs and would be a non-breaking change. Would this address your use case? Option B:
Could have unexpected consequences for others. I feel |
Indeed, your option A, with 200 on line 204 and possibly 500 between lines 206-207 not only solves the original issue, but is also a superior solution to what I was proposing. For now I am using the workaround above but I believe it would be worth including in the future major release. Thank you. |
I've started a draft for v4. I think this is what we landed on: ebd59e5#diff-ff075fc97631986a9236dd1e4f9a06cff63228e65b3a8b7922eb5b36f23d0002 |
Perfect, thank you for solving this. |
Middy util contains a
normalizeHttpResponse
method, which has a behavior that seems potentially confusing and inconsistent with "native" AWS Labmda - AWS Gateway integration.The function of the
normalizeHttpResponse
method is, in short: when the response is a simple object or a string, encapsulate it into abody
attribute of a structured response.That is similar to what AWS Gateway does natively when it gets a string or an object as a response - it uses the object/string as a body, returning it with a 200 status code, as described in the documentation.
However, the Middy normalization causes a strange / unintuitive behavior. On an example of a simple lambda returning
{"hello": "world"}
, when it is called by AWS Gateway directly, client indeed receives'{"hello":"world"}'
as expected, however when Middy with some middleware using normalization is used (e.g. httpSecurityHeadersMiddleware), client receives an unexpected response such as:'{"body":{"hello":"world"},"headers":"..."}'
.I believe this is almost never the intention (e.g. the security headers here do not work) and the behavior would be more reasonable and more consistent with native API Gateway experience if the
normalizeHttpResponse
also made the same "statusCode=200 if missing" assumption as the AWS Gateway does. I.e. in its source add:Sorry if I am missing some case where the current behavior is required.
Thank you for Middy.
The text was updated successfully, but these errors were encountered: