-
Notifications
You must be signed in to change notification settings - Fork 114
Open
Description
impl HttpContext for HttpHeadersBody {
fn on_http_request_body(&mut self, body_size: usize, end_of_stream: bool) -> Action {
if !end_of_stream {
return Action::Pause;
}
info!("on_http_request_body");
match self.get_shared_data("changed") {
(change, _) => {
match change {
None => {}
Some(c) => {
info!("context-{}, changed:{}",self.context_id, String::from_utf8(c).unwrap());
return Action::Continue;
}
}
}
}
self.dispatch_http_call(
"httpbin",
vec![
(":method", "GET"),
(":path", "/bytes/1"),
(":authority", "httpbin.org"),
],
None,
vec![],
Duration::from_secs(5),
)
.unwrap();
Action::Pause
}
}
impl Context for HttpHeadersBody {
fn on_http_call_response(&mut self, _: u32, _: usize, body_size: usize, _: usize) {
info!("on_http_call_response");
if let Some(body) = self.get_http_call_response_body(0, body_size) {
if !body.is_empty() {
let mod_body = "modify body";
self.set_http_request_body(0, mod_body.as_bytes().len(), mod_body.as_bytes());
self.set_shared_data("changed", Some("true".as_bytes()), None);
self.resume_http_request();
return;
}
}
info!("Access forbidden.");
self.send_http_response(
403,
vec![("Powered-By", "proxy-wasm")],
Some(b"Access forbidden.\n"),
);
}
}
Metadata
Metadata
Assignees
Labels
No labels