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

proxy_get_header_map_value: early return when header not found #3

Merged
merged 1 commit into from
Jun 5, 2024

Conversation

eguzki
Copy link

@eguzki eguzki commented May 29, 2024

What

When header was not found, the testing framework was panic'ing.

Returning Status::NotFound instead as expected by Proxy-wasm-sdk library.

pub fn get_map_value_bytes(map_type: MapType, key: &str) -> Result<Option<Bytes>, Status> {
    let mut return_data: *mut u8 = null_mut();
    let mut return_size: usize = 0;
    unsafe {
        match proxy_get_header_map_value(
            map_type,
            key.as_ptr(),
            key.len(),
            &mut return_data,
            &mut return_size,
        ) {
            Status::Ok => {
                if !return_data.is_null() {
                    Ok(Some(Vec::from_raw_parts(
                        return_data,
                        return_size,
                        return_size,
                    )))
                } else {
                    Ok(None)
                }
            }
            Status::NotFound => Ok(None),
            status => panic!("unexpected status: {}", status as u32),
        }
    }
}

@eguzki eguzki requested a review from alexsnaps May 29, 2024 16:26
@eguzki eguzki merged commit 63433ea into kuadrant Jun 5, 2024
@eguzki eguzki deleted the fix-get-proxy_get_header_map_value-when-not-found branch June 5, 2024 15:37
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

Successfully merging this pull request may close these issues.

2 participants