-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wasm: fix order of callbacks for paused requests. (#13840)
Fixes proxy-wasm/proxy-wasm-rust-sdk#43. Signed-off-by: Piotr Sikora <piotrsikora@google.com>
- Loading branch information
1 parent
2a25296
commit 4889735
Showing
8 changed files
with
180 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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
39 changes: 39 additions & 0 deletions
39
test/extensions/filters/http/wasm/test_data/resume_call_rust.rs
This file contains 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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use log::info; | ||
use proxy_wasm::traits::{Context, HttpContext}; | ||
use proxy_wasm::types::*; | ||
use std::time::Duration; | ||
|
||
#[no_mangle] | ||
pub fn _start() { | ||
proxy_wasm::set_log_level(LogLevel::Trace); | ||
proxy_wasm::set_http_context(|_, _| -> Box<dyn HttpContext> { Box::new(TestStream) }); | ||
} | ||
|
||
struct TestStream; | ||
|
||
impl HttpContext for TestStream { | ||
fn on_http_request_headers(&mut self, _: usize) -> Action { | ||
self.dispatch_http_call( | ||
"cluster", | ||
vec![(":method", "POST"), (":path", "/"), (":authority", "foo")], | ||
Some(b"resume"), | ||
vec![], | ||
Duration::from_secs(1), | ||
) | ||
.unwrap(); | ||
info!("onRequestHeaders"); | ||
Action::Pause | ||
} | ||
|
||
fn on_http_request_body(&mut self, _: usize, _: bool) -> Action { | ||
info!("onRequestBody"); | ||
Action::Continue | ||
} | ||
} | ||
|
||
impl Context for TestStream { | ||
fn on_http_call_response(&mut self, _: u32, _: usize, _: usize, _: usize) { | ||
info!("continueRequest"); | ||
self.resume_http_request(); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
test/extensions/filters/http/wasm/test_data/test_resume_call_cpp.cc
This file contains 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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// NOLINT(namespace-envoy) | ||
#include <memory> | ||
#include <string> | ||
#include <unordered_map> | ||
|
||
#ifndef NULL_PLUGIN | ||
#include "proxy_wasm_intrinsics_lite.h" | ||
#else | ||
#include "extensions/common/wasm/ext/envoy_null_plugin.h" | ||
#endif | ||
|
||
START_WASM_PLUGIN(HttpWasmTestCpp) | ||
|
||
class ResumeCallContext : public Context { | ||
public: | ||
explicit ResumeCallContext(uint32_t id, RootContext* root) : Context(id, root) {} | ||
|
||
FilterHeadersStatus onRequestHeaders(uint32_t, bool) override; | ||
FilterDataStatus onRequestBody(size_t, bool) override; | ||
}; | ||
|
||
class ResumeCallRootContext : public RootContext { | ||
public: | ||
explicit ResumeCallRootContext(uint32_t id, std::string_view root_id) | ||
: RootContext(id, root_id) {} | ||
}; | ||
|
||
static RegisterContextFactory register_ResumeCallContext(CONTEXT_FACTORY(ResumeCallContext), | ||
ROOT_FACTORY(ResumeCallRootContext), | ||
"resume_call"); | ||
|
||
FilterHeadersStatus ResumeCallContext::onRequestHeaders(uint32_t, bool) { | ||
auto context_id = id(); | ||
auto resume_callback = [context_id](uint32_t, size_t, uint32_t) { | ||
getContext(context_id)->setEffectiveContext(); | ||
logInfo("continueRequest"); | ||
continueRequest(); | ||
}; | ||
if (root()->httpCall("cluster", {{":method", "POST"}, {":path", "/"}, {":authority", "foo"}}, | ||
"resume", {}, 1000, resume_callback) != WasmResult::Ok) { | ||
logError("unexpected failure"); | ||
return FilterHeadersStatus::StopIteration; | ||
} | ||
logInfo("onRequestHeaders"); | ||
return FilterHeadersStatus::StopIteration; | ||
} | ||
|
||
FilterDataStatus ResumeCallContext::onRequestBody(size_t, bool) { | ||
logInfo("onRequestBody"); | ||
return FilterDataStatus::Continue; | ||
} | ||
|
||
END_WASM_PLUGIN |
This file contains 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