Skip to content

lua: Add setBytes() API to the buffer wrapper#13172

Merged
dio merged 4 commits intoenvoyproxy:masterfrom
dio:lua-set-bytes
Sep 22, 2020
Merged

lua: Add setBytes() API to the buffer wrapper#13172
dio merged 4 commits intoenvoyproxy:masterfrom
dio:lua-set-bytes

Conversation

@dio
Copy link
Member

@dio dio commented Sep 18, 2020

Commit Message: This patch adds setBytes() API to the buffer wrapper by making the wrapped buffer to be mutable. This allows rewriting upstream data in the response path.

Risk Level: Low
Testing: Added unit and integration tests.
Docs Changes: Added
Release Notes: Added
Fixes #5998

Signed-off-by: Dhi Aurrahman dio@tetrate.io

dio added 3 commits September 18, 2020 15:27
This patch adds setBytes() API to the buffer wrapper by making the
wrapper buffer to be mutable. This allows rewriting upstream data in the
response path.

Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! LGTM!

@dio dio merged commit f63c27c into envoyproxy:master Sep 22, 2020
@dio dio deleted the lua-set-bytes branch September 22, 2020 05:59
@ceastman-ibm
Copy link

@dio do you have an example of lua code to do this?

@dio
Copy link
Member Author

dio commented Sep 22, 2020

@ikingye
Copy link

ikingye commented Jan 11, 2021

in the response path.

Why not in the request path?

@dio
Copy link
Member Author

dio commented Jan 11, 2021

@ikingye do you mean you want to add more data to the request to upstream as well?

@SergeiCherevko
Copy link

@dio Hello!
Please can you tell me how i can get concatenation in "setBytes"? For example i have body "hello" and i need to push to upstream body "123_hello", but its not working ((

                  - name: envoy.filters.http.lua
                    typed_config:
                      "@type": type.googleapis.com/envoy.extensions.filters.http.lua.v3.Lua
                      default_source_code:
                        inline_string:
                          function envoy_on_request(request_handle)
                            local body = request_handle:body()
                            body:setBytes("123_" .. body)
                          end

@ssapunkova
Copy link

Hello, @dio. Does this allow to rewrite the downstream data (envoy_on_request) as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: In lua http filter add ability to set the contents of the body

6 participants