proxy-wasm / proxy-wasm-rust-sdk

WebAssembly for Proxies (Rust SDK)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How do I acquire the query string from a request?

cetanu opened this issue · comments

Hey folks,

I tried looking at past issues, and through the traits, however I can't find where I would obtain the query string from a request.

I have also tried getting the :path header, however in my testing, this does not include the query string.

I am simply using self.get_http_request_header(":path") currently. The RFC for http/2 states that this is where the query string should be.

Am I perhaps doing something quite wrong?

Example code...

use log::info;
use proxy_wasm::traits::*;
use proxy_wasm::types::*;

proxy_wasm::main! {{
    proxy_wasm::set_log_level(LogLevel::Trace);
    proxy_wasm::set_root_context(|_| -> Box<dyn RootContext> { Box::new(WasmFilter) });
}}

struct WasmFilter;

impl Context for WasmFilter {}

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

    fn create_http_context(&self, _context_id: u32) -> Option<Box<dyn HttpContext>> {
        Some(Box::new(WasmFilter {}))
    }
}

impl HttpContext for WasmFilter {
    fn on_http_request_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action {
        if let Some(path) = self.get_http_request_header(":path") {
            if !path.contains("?") {
                // No query string, skip
                info!("Path does not have query string: {}", path);
                return Action::Continue
            }
        }
        Action::Continue
    }
}

Nevermind... I can sometimes get the query string... Something weird going on with my http tests