-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
feat(aws-lambda) add support for forwarded request method/uri/body #2823
Conversation
7846bc2
to
df757ba
Compare
kong/tools/public.lua
Outdated
map_type = 3 | ||
req_mime = MIME_TYPES.form_url_encoded | ||
|
||
elseif str_find(content_type, "application/xml", nil, true) then |
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.
I think it's better to add "text/xml" (for SOAP 1.1 etc) and "application/soap+xml" (for SOAP 1.2)
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.
👍
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.
I feel like SOAP should be made into its own MIME type (in the above MIME_TYPE
enum), but let's maybe keep it as XML for now.
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.
Added in the latest revision of this patch!
The pull request solves the issue I addressed in #2470 with the exception of Content-type: text/xml and Content-type: application/soap+xml |
Did you notice a few of the differences, namely:
Are you fine with those changes and do they impact one of your use-cases? |
df757ba
to
b3bd2d2
Compare
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.
two minor comments, lgtm otherwise
kong/plugins/aws-lambda/handler.lua
Outdated
local body_args, err_code, body_raw = public_utils.get_body_info() | ||
if err_code == public_utils.req_body_errors.unknown_ct then | ||
-- don't know what this body MIME type is, base64 it just in case | ||
body_raw = ngx_encode_base64(body_raw) |
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.
initially i was thinking im not entirely sure about this approach. what about content types that are already base64 encoded. perhaps a flag to encode unknown types vs. passing them through. but not a blocker, and we start to run into edge case territory here
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.
I'm wondering if it's worse to insert property indicates that body has been base64 encoded (when it's done in plugin) into request to lambda
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.
I'm wondering if it's worse to insert property indicates that body has been base64 encoded (when it's done in plugin) into request to lambda
Yes, I was having the same thought. Something like upstream_body.request_body.base64 = true
maybe? We could also not send what we think is binary data to the function - until someone comes to us with a good-case for that? Do you already have such a use-case for processing binary data in Lambda functions?
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.
@thibaultcha "upstream_body.request_body.base64 = true" - sounds good. The use case for sending binary to lambda is replacing with lambda some existing services that are using binary protocols (or just compressed data to decrease traffic) for instance: fastinfoset, avro, protobuf. Also AWS API Gateway supports binary content https://aws.amazon.com/blogs/compute/binary-support-for-api-integrations-with-amazon-api-gateway/
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.
@akh00 Flag added! ;)
kong/plugins/aws-lambda/handler.lua
Outdated
body_raw = ngx_encode_base64(body_raw) | ||
end | ||
|
||
if conf.forward_request_body or conf.forward_request_headers |
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.
extra whitespace in front of or
|
b3bd2d2
to
86fbe37
Compare
How can I help to get this merged? |
@decoursin @akh00 At this point, I believe we only need docs to be written for this new feature. Docs are open source and can be modified here: https://github.com/Mashape/getkong.org I would very much like for open source contributors to be responsible for writing docs as well, instead of dropping the burden on the Kong team, who is already very busy :) Thanks! |
Here, I've updated docs for |
@thibaultcha @p0pr0ck5 @decoursin Added pull request with updated documentation Kong/docs.konghq.com#506 |
Can we please merge this now? |
@decoursin If you really need this, feel free to apply the patch yourself and you could use it as of today. Even merged, this won't be released until 0.11.1, for which we don't have a release date yet. The Kong team is extremely busy with its own road-map already. |
Options added in Kong/kong#2823 Signed-off-by: Thibault Charbonnier <[email protected]>
86fbe37
to
8381735
Compare
New optional configuration properties: - `forward_request_method` - `forward_request_uri` - `forward_request_headers` - `forward_request_body` If specified, the request body sent to the invoked Lambda will contain the desired attributes of the client's request as a JSON payload. If none of the above values are specified, the upstream body contains a JSON payload which is merged from the request's body data and its query string. This is to preserve backwards compatibility with previous versions of this plugin. Original patch from Andrei Kishkevich <[email protected]> Reworked by Thibault Charbonnier <[email protected]> Signed-off-by: Thibault Charbonnier <[email protected]>
8381735
to
6d6e68b
Compare
@akh00 @decoursin Merged! 🎉 Thanks both of you for your help and contributions! |
Options added in Kong/kong#2823 Signed-off-by: Thibault Charbonnier <[email protected]>
Options added in Kong/kong#2823 Signed-off-by: Thibault Charbonnier <[email protected]>
Summary
Depends on: #2822
Reworked version of #2470 from @akh00.
This fixes a few issues with #2470 regarding inconsistent request body parsing, some inconsistent naming for the new schema values and a slightly different approach regarding the forging of the forwarded upstream request body. It also addresses quite a few style and maintainability issues.
Full changelog
New optional configuration properties:
forward_request_method
forward_request_uri
forward_request_headers
forward_request_body
If specified, the request body sent to the invoked Lambda will contain
the desired attributes of the client's request as a JSON payload.
If none of the above values are specified, the upstream body contains a
JSON payload which is merged from the request's body data and its
query string. This is to preserve backwards compatibility with previous
versions of this plugin.
Issues resolved
Fix #2379
Fix #2469