proxy-wasm / proxy-wasm-rust-sdk

WebAssembly for Proxies (Rust SDK)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is it possible to make HTTP call from fn on_http_request_headers method?

iandrosov opened this issue · comments

Use case for this is custom Auth policy for Envoy often needs to make additional validation HTTP requests to IDP services as example to validate header values or possibly chain 2 calls to get final OK to Continue.

Looking at on_http_request_headers function and Rust HTTP Client calls it seem those are not compatible even if we use reqwest::blocking::Client. Is this something that can be done in the context of WASM custom policy for Envoy or NOT?
Using this sample code inside a function while it works in Rust code it does not seem to be compatible with proxi-wasm ABI

let client = Client::new();
let resp = client.post("http://httpbin.org/post")
.body("Send secret code to validate")
.send()?;
if resp.status() == StatusCode::OK {
println!("RESULT 200");
return Action::Continue;
}else{
println!("RESULT ERROR");
}

This code cannot compile due to errors like this one of them cannot use the ? operator in a method that returns proxy_wasm::types::Action

It possible to make HTTP calls (see: examples/http_auth_random.rs), but not using reqwest::blocking::Client.