You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi @thinhtranquoc. While the calls will always technically be async (as we don't want to block Envoy, we're on the critical request path!), there is a way to do what I believe you're probably trying to do, which is essentially:
Receive a request in Envoy
Send a request to some external service
Wait for the response
If the response fits some criteria, allow continue, otherwise reject request.
You can do this by making an async request, pausing via a StopIteration, and then in the callback if everything looks good you can resume iteration with a call to proxy_continue_stream.
I see an example for httpcall
https://github.com/envoyproxy/envoy-wasm/blob/dfb104874b3babc7e676aaa0199f2926410c0671/test/extensions/filters/http/wasm/test_data/async_call_cpp.cc#L15
I have a question. How to not using async in this case? Because I want to return the result of the external API.
auto callback = [context_id](uint32_t headerCount, size_t body_size, uint32_t trailerCount) {
WasmDataPtr wdpGhmv = getHeaderMapValue(WasmHeaderMapType::HttpCallResponseHeaders, ":status");
uint32_t status = std::stoi(wdpGhmv->toString());
WasmDataPtr wdpBody = getBufferBytes(WasmBufferType::HttpCallResponseBody, 0, body_size);
std::string reponse = wdpBody->toString();
getContext(context_id)->setEffectiveContext();
if (status == 200){
sendLocalResponse(428, "Precondition Required", reponse, {});
return FilterHeadersStatus::StopIteration;
}
};
The text was updated successfully, but these errors were encountered: