Created
October 23, 2020 08:38
-
-
Save eloycoto/3b6036b6995b17730a4ab068f5a0e3e8 to your computer and use it in GitHub Desktop.
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
use log::trace; | |
use proxy_wasm::traits::*; | |
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(HttpAuthRandom) }); | |
} | |
struct HttpAuthRandom; | |
impl HttpContext for HttpAuthRandom { | |
fn on_http_request_headers(&mut self, _: usize) -> Action { | |
log::info!("ON HTTP REQUEST HEADERS"); | |
let res = self.dispatch_http_call( | |
"web_service", | |
vec![ | |
(":method", "GET"), | |
(":path", "/bytes/1"), | |
(":authority", "httpbin.org"), | |
], | |
None, | |
vec![], | |
Duration::from_secs(5), | |
); | |
log::info!("REsult-->{:?}", res); | |
Action::Pause | |
} | |
} | |
impl Context for HttpAuthRandom { | |
fn on_http_call_response(&mut self, _: u32, _: usize, body_size: usize, _: usize) { | |
self.resume_http_request(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment