Skip to content

Commit

Permalink
dist: upgrade to proxy-wasm@0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Swaagie committed Apr 9, 2022
1 parent e0a5f51 commit ecaa6db
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "envoy-rbi-filter"
description = "Envoy Response Body Injection Filter"
version = "0.1.0"
version = "0.2.0"
authors = ["Martijn Swaagman <martijn@swaagman.online>"]
edition = "2021"
license = "MIT"
Expand All @@ -16,7 +16,7 @@ path = "src/lib.rs"
crate-type = ["cdylib"]

[dependencies]
proxy-wasm = "0.1.4"
proxy-wasm = "0.2.0"
serde_json = "1.0.78"
log="0.4.14"

Expand Down
9 changes: 4 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ use log::debug;
use proxy_wasm::traits::*;
use proxy_wasm::types::*;

#[no_mangle]
pub fn _initialize() {
proxy_wasm::main! {{
proxy_wasm::set_log_level(LogLevel::Trace);
proxy_wasm::set_root_context(|_| -> Box<dyn RootContext> {
Box::new(ResponseBodyInjectionConfig {
config: HashMap::new(),
})
});
}
}}

const ECHO: &str = "<!--#echo";
const END: &str = "-->";
Expand Down Expand Up @@ -53,7 +52,7 @@ impl HttpContext for ResponseBodyInjectionFilter {
Action::Continue
}

fn on_http_response_headers(&mut self, _: usize) -> Action {
fn on_http_response_headers(&mut self, _: usize, _: bool) -> Action {
// Remove content-length since it's augmented and let clients decide
self.set_http_response_header("content-length", None);
self.set_http_response_header("Powered-By", Some("x-envoy-rbi-filter"));
Expand All @@ -70,7 +69,7 @@ impl Context for ResponseBodyInjectionConfig {}

impl RootContext for ResponseBodyInjectionConfig {
fn on_configure(&mut self, _: usize) -> bool {
let configuration: Vec<u8> = self.get_configuration().unwrap_or_default();
let configuration: Vec<u8> = self.get_plugin_configuration().unwrap_or_default();

match serde_json::from_slice(&configuration) {
Ok(config) => self.config = config,
Expand Down

0 comments on commit ecaa6db

Please sign in to comment.