> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gcore.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Build and deploy a FastEdge CDN application

> Build and deploy a FastEdge CDN application by writing a handler, compiling it to WebAssembly, and uploading the binary.

FastEdge CDN applications run inside a CDN resource's request pipeline and can inspect or modify requests and responses as they pass through the CDN.

Complete the [Rust (CDN / Proxy-Wasm)](/fastedge/getting-started/setup-rust-cdn) setup before proceeding. Once deployed, attach the application to a CDN resource to process live traffic — that step is in [CDN applications](/fastedge/getting-started/integrate-cdn-with-fastedge).

## Write a handler

A CDN application consists of two parts: a root context that registers the filter factory, and a filter that implements the callbacks. Replace `src/lib.rs` with:

```rust theme={null}
use proxy_wasm::traits::*;
use proxy_wasm::types::*;

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

struct Root;
impl Context for Root {}
impl RootContext for Root {
    fn create_http_context(&self, _: u32) -> Option<Box<dyn HttpContext>> {
        Some(Box::new(Filter))
    }
    fn get_type(&self) -> Option<ContextType> {
        Some(ContextType::HttpContext)
    }
}

struct Filter;
impl Context for Filter {}
impl HttpContext for Filter {
    fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action {
        self.add_http_request_header("x-fastedge", "cdn");
        Action::Continue
    }
}
```

`Root` registers a new `Filter` for each incoming request via `create_http_context`. `on_http_request_headers` runs when the CDN receives request headers — this example adds a custom `x-fastedge` header and returns `Action::Continue` to pass the request downstream unchanged. To stop the request instead, return `Action::Pause`.

> [!WARNING]
>
> Do not set request headers with the `x-cdn-` or `x-gcdn-` prefixes. The CDN reserves these names for internal use and strips them before the request reaches the origin. The Proxy-Wasm header APIs do not return an error when the application sets a reserved name, so the header appears to be set in the app but never arrives at the origin.

## Build

Compile the handler to a WebAssembly binary. The first build downloads dependencies and takes one to two minutes.

```sh theme={null}
cargo build --release --target wasm32-wasip1
```

The binary is at `./target/wasm32-wasip1/release/my_cdn_app.wasm`. This file is uploaded to FastEdge in the next step.

## Deploy
