ERROR because it doesn't implement `std::fmt::Debug`

I have the following code but I have always the same mistake, I just wanna make a simple HTTP Request. PLEASE HELP

use proxy_wasm::traits::;
use proxy_wasm::types::
;
use serde::Deserialize;
use log::{info};
use reqwest;

proxy_wasm::main! {{
proxy_wasm::set_log_level(LogLevel::Trace);
proxy_wasm::set_root_context(|_| -> Box {
Box::new(CustomAuthRootContext {
config: CustomAuthConfig::default(),
})
});
}}

//IT SEEMS THAT IS THE DEFINITION OF THE CLASS STRUCTURE CustomAuthRootContext THAT IS THE ONE THAT "MATCHES OR DETECTS THE HTTP PROTOCOL"
struct CustomAuthRootContext {
config: CustomAuthConfig,
}

//FUNCTION THAT GETS THE VALUE THAT WE DEFINE IN THE CONFIGURATION WHEN WE APPLIED THE CUSTOM POLIY
#[derive(Default, Clone, Deserialize)]
struct CustomAuthConfig {

#[serde(alias = "dapiUrl")]
secret_value: String,

}

//IT SEEMS THAT IS THE DEFINITION OF THE CLASS STRUCTURE CustomAuthHttpContext THAT IS THE ONE THAT EXECUTES "ACTIONS" ONCE THE HTTP TRANSACTION IS BEING EXECUTED.
struct CustomAuthHttpContext {
pub config: CustomAuthConfig,
}

impl Context for CustomAuthRootContext {}

impl Context for CustomAuthHttpContext {}

//AS THE FIRST WORD SAYS, IS THE IMPLEMENTATION FOR THE METHOR CustomAuthHttpContext
//THAT SEEMS IS THE PRINCIPAL ONCE THE HTTP TRANSACTION STARTS
impl HttpContext for CustomAuthHttpContext {
fn on_http_request_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action {

    info!("STARTING POLICY!!");
    let client = reqwest::Client::new();
    let _res = client.post("http://httpbin.org/post")
        .body("the exact body that is sent")
        .send();

    println!("body = {:?}", _res);


    if let Some(value) = self.get_http_request_header("x-custom-auth") {
        info!("the answer was: {:?}", value);

        if self.config.secret_value == value {
            return Action::Continue;
        }
    }

    self.send_http_response(401, Vec::new(), None);

    Action::Pause
}

}
//AS THE FIRST WORD SAYS, IS THE IMPLEMENTATION FOR THE METHOD CustomAuthRootContext
//THAT SEEMS IS THE ONE WHERE YOU CAN DEFINE THE INIZILIZATION OF METHODS OR SOMETHING LIKE THAT
//BEFORE ANY TRANSACTION BEGIN.... THIS IS THE METHOD THAT LESS UNDERSTAND.
impl RootContext for CustomAuthRootContext {

fn on_configure(&mut self, _: usize) -> bool {
        if let Some(config_bytes) = self.get_plugin_configuration() {
            self.config = serde_json::from_slice(config_bytes.as_slice()).unwrap();
        }

        true
    }

fn create_http_context(&self, _: u32) -> Option<Box<dyn HttpContext>> {
    Some(Box::new(CustomAuthHttpContext {
        config: self.config.clone(),
    }))
}

fn get_type(&self) -> Option<ContextType> {
    Some(ContextType::HttpContext)
}

}

What error to you get?

Thanks Lutz!

The error that I am having is the one of the image.

The text is

$ cargo build --target wasm32-unknown-unknown --release
Compiling custom_authorizer_policy v0.1.0 ()
error[E0277]: impl Future<Output = Result<Response, reqwest::Error>> doesn't implement std::fmt::Debug
--> src/lib.rs:53:33
|
53 | println!("body = {:?}", _res);
| ^^^^ impl Future<Output = Result<Response, reqwest::Error>> cannot be formatted using {:?} because it doesn't implement std::fmt::Debug
|
= help: the trait std::fmt::Debug is not implemented for impl Future<Output = Result<Response, reqwest::Error>>
= note: this error originates in the macro $crate::format_args_nl (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try rustc --explain E0277.
error: could not compile custom_modere_authorizer_policy due to previous error

I suspect there is an await missing somewhere before the println!.

Correct. You have to await the future returned by the send method from the http client.

For future reference, please format your code as follows:

```
Your code here
```

Which transforms this eyesore:

fn main() {
println!();
}

Into this:

fn main() {
    println!();
}
3 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.