Documentation
pdk-0.0.0-alpha.5 has been yanked.

Policy Development Kit (PDK)   Latest Version pdk msrv

pdk is the primary crate for building Flex Gateway custom policies.


You may be looking for:

pdk in action

[dependencies]
pdk = { version = "1.6" }
use anyhow::{anyhow, Result};

use pdk::hl::*;

use crate::generated::config::Config;

// handle the headers on the incoming http request.
async fn request_filter(request_state: RequestState, _config: &Config) {
    let headers_state = request_state.into_headers_state().await;

    // Replace the current value of the header 'example-replaced-header' with the value 'example-replaced-value'
    headers_state.handler().set_header("example-replaced-header", "example-replaced-value");
}

#[entrypoint]
async fn configure(launcher: Launcher, Configuration(bytes): Configuration) -> Result<()> {
    let config: Config = serde_json::from_slice(&bytes).map_err(|err| {
        anyhow!(
            "Failed to parse configuration '{}'. Cause: {}",
            String::from_utf8_lossy(&bytes),
            err
        )
    })?;

    let filter = on_request(|rs| request_filter(rs, &config));
    launcher.launch(filter).await?;
    Ok(())
}

License