-
Notifications
You must be signed in to change notification settings - Fork 343
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
Lambda-http: vary type of response based on request origin #269
Conversation
ApiGatewayV2, ApiGateway and Alb all expect different types of responses to be returned from the invoked lambda function. Thus, it makes sense to pass the request origin to the creation of the response, so that the correct type of LambdaResponse is returned from the function. This commit also adds support for the "cookies" attribute which can be used for returning multiple Set-cookie headers from a lambda invoked via ApiGatewayV2, since ApiGatewayV2 no longer seems to recognize the "multiValueHeaders" attribute. Closes: awslabs#267.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is excellent.
At first there was only rest apis ... and then albs.. and then http apis.
When we got to supporting three types the current impl didn't feel right but this feels a lot cleaner and provides an way forward when the inevitable 4th http like trigger comes along
@@ -149,7 +152,7 @@ where | |||
|
|||
#[doc(hidden)] | |||
pub struct TransformResponse<R, E> { | |||
is_alb: bool, | |||
request_origin: RequestOrigin, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much cleaner
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be awesome if this got merged into master @davidbarsky.
An honest question: why is this runtime maintaining its own implementation of the AWS Events where one could get them from the |
Issue #, if available:
#267
Description of changes:
ApiGatewayV2, ApiGateway and Alb all expect different types of responses to be returned from the invoked lambda function. Thus, it makes sense to pass the request origin to the creation of the response, so that the correct type of LambdaResponse is returned from the function.
This PR also adds support for the "cookies" attribute which can be used for returning multiple Set-cookie headers from a lambda invoked via ApiGatewayV2, since ApiGatewayV2 no longer seems to recognize the "multiValueHeaders" attribute.
On lines 129-132 of
response.rs
theSET_COOKIE
headers are removed from theheaders
returned to API Gateway v2, because otherwise API Gateway v2 would return threeset-cookie
headers when just returning two cookies incookies
, because one of the cookies would be duplicated in theheaders
. I tried using thehttp::header::OccupiedEntry::remove_entry_mult
function for removing theSET_COOKIE
headers from theheaders
, but I got some panicking from the http crate as described in hyperium/http#446. So I went with the solution where I first fetch theSET_COOKIE
headers returned withheaders.get_all
and insert them cloned into thecookies
, and then remove them withheaders.remove(SET_COOKIE)
. However, any ideas and suggestions as to improve this are warmly welcome!By submitting this pull request