-
Notifications
You must be signed in to change notification settings - Fork 5.5k
lua: add fire-and-forget functionality to http call #10145
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
Merged
+311
−71
Merged
Changes from 34 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
871ee1b
extract http call functions into a new class, LuaFilterLibrary
mindyor df9df09
create fire and forget listener; lua function httpCallAsync
mindyor 541bc4b
group class functions together
mindyor 8b5b84d
add documentation for httpCallAsync
mindyor 323d728
add release note to version history
mindyor e892eaa
formatting
mindyor 29464ba
naming. s/LuaFilterLibrary/LuaFilterUtil/
mindyor b566eab
formatting: lengthen underline
mindyor 4cb0ecc
move instantiation of fire and forget writer into stream handle wrapp…
mindyor 27a0f3c
makeHttpCall static function
mindyor 11c1301
whitespace
mindyor 21aa51e
alphabetic order
mindyor bf9998d
delete fire and forget writer in destructor
mindyor 3e0f6c4
correct docs: httpCallAsync return
mindyor 38a8a99
rename functions Nonblocking as implementation does not use callbacks
mindyor 67aee6e
rename FireAndForgetWriter to FireAndForgetHttpWriter
mindyor e5bee45
comment nits
mindyor ac562dd
comment clarity for fire and forget http wrier
mindyor aa04eb8
remove superfluous else
mindyor d838492
formatting
mindyor 7b234f3
put helper methods in anonymous namespace
mindyor f4cd746
rename callbacksListener to callbacks
mindyor d6e452b
use simple noop callbacks class rather than fire and forget writer
mindyor d022924
httpCall take flag to indicate asynchronous. Remove httpCallNonblocking
mindyor 5ad50d1
test covering async = false case
mindyor 55d1682
remove lua declaration of functions; update naming and comments to us…
mindyor 1ebaac1
Merge branch 'master' into async-lua-http-call
mindyor f279ad2
use static noopcallback - thanks snowp
mindyor 1594207
remove unused lines in test
mindyor 9945ac5
integration test assert on header values - thanks snowp
mindyor 1d4ba85
comment tweak
mindyor 6dcdcf5
pr comments
mindyor 8459416
type check for async flag
mindyor d190e36
formatting
mindyor 9a1dbd7
review feedback nits
mindyor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,6 +86,8 @@ class FilterCallbacks { | |
|
|
||
| class Filter; | ||
|
|
||
| class NoopCallbacks; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this needs forward declaration? |
||
|
|
||
| /** | ||
| * A wrapper for a currently running request/response. This is the primary handle passed to Lua. | ||
| * The script interacts with Envoy entirely through this handle. | ||
|
|
@@ -156,6 +158,8 @@ class StreamHandleWrapper : public Filters::Common::Lua::BaseLuaObject<StreamHan | |
| * @param 2 (table): A table of HTTP headers. :method, :path, and :authority must be defined. | ||
| * @param 3 (string): Body. Can be nil. | ||
| * @param 4 (int): Timeout in milliseconds for the call. | ||
| * @param 5 (bool): Optional flag. If true, filter continues without waiting for HTTP response | ||
| * from upstream service. False/synchronous by default. | ||
| * @return headers (table), body (string/nil) | ||
| */ | ||
| DECLARE_LUA_FUNCTION(StreamHandleWrapper, luaHttpCall); | ||
|
|
@@ -247,7 +251,8 @@ class StreamHandleWrapper : public Filters::Common::Lua::BaseLuaObject<StreamHan | |
| */ | ||
| DECLARE_LUA_CLOSURE(StreamHandleWrapper, luaBodyIterator); | ||
|
|
||
| static void buildHeadersFromTable(Http::HeaderMap& headers, lua_State* state, int table_index); | ||
| int luaHttpCallSynchronous(lua_State* state); | ||
| int luaHttpCallAsynchronous(lua_State* state); | ||
|
|
||
| // Filters::Common::Lua::BaseLuaObject | ||
| void onMarkDead() override { | ||
|
|
@@ -287,6 +292,17 @@ class StreamHandleWrapper : public Filters::Common::Lua::BaseLuaObject<StreamHan | |
| Http::AsyncClient::Request* http_request_{}; | ||
| }; | ||
|
|
||
| /** | ||
| * An empty Callbacks client. It will ignore everything, including successes and failures. | ||
| */ | ||
| class NoopCallbacks : public Http::AsyncClient::Callbacks { | ||
| public: | ||
| // Http::AsyncClient::Callbacks | ||
| void onSuccess(Http::ResponseMessagePtr&&) override {} | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: del newline |
||
| void onFailure(Http::AsyncClient::FailureReason) override {} | ||
| }; | ||
|
|
||
| /** | ||
| * Global configuration for the filter. | ||
| */ | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit:
async_flag_index