Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_property and set_property not working in Network filter #214

Open
vovkman opened this issue Oct 31, 2023 · 0 comments
Open

get_property and set_property not working in Network filter #214

vovkman opened this issue Oct 31, 2023 · 0 comments

Comments

@vovkman
Copy link

vovkman commented Oct 31, 2023

I have a wasm network plugin where I want to read a property that contains the value of an http header. I need this header so that I can know who belongs to a given stream.

The header value can be found in an http wasm filter easily like so (I get the actual api key back)

impl HttpContext for HttpHeaders {
    fn on_http_response_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action {
        let api_key = self
            .get_property(vec!["metadata", "filter_metadata", "envoy.lb", "api-key"])
            .map_or(Ok("no value set".to_string()), String::from_utf8)
            .unwrap_or("couldn't covert".to_string());
        proxy_wasm::hostcalls::log(
            LogLevel::Info,
            format!("on_http_response_headers: {:?}", api_key).as_str(),
        );
        Action::Continue
    }
}

But if I put the same code in a network filter, I always get back "no value set"

impl StreamContext for MeterTcp {
    fn on_upstream_data(&mut self, _data_size: usize, _end_of_stream: bool) -> Action {
        let api_key = self
            .get_property(vec!["metadata", "filter_metadata", "envoy.lb", "api-key"])
            .map_or(Ok("no value set".to_string()), String::from_utf8)
            .unwrap_or("couldn't covert".to_string());
        proxy_wasm::hostcalls::log(
            LogLevel::Info,
            format!("on_upstream_data: {:?}", api_key).as_str(),
        );
        Action::Continue
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant