---
schema_version: "1"
id: d0120095ac07884af977803fd148e7fef69993ccd2cf667823555244ddac663a
title: Stopping Request Execution
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/pdk/1.6/policies-pdk-configure-features-stop.md
canonical_url: https://docs.mulesoft.com/pdk/1.6/policies-pdk-configure-features-stop
source_site: docs.mulesoft.com
content_type: documentation
content_hash: b1aa2a80e4b41d55e95ab8c07152079763ba93a530ca13423138730e1a87adcb
description: MuleSoft Documentation Site
release: "1.6"
latest: false
---
---
product: Omni Gateway Policy Development Kit (PDK)
version: 1.6
---

# Stopping Request Execution

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

To intercept and stop a request, return a `Response` object from your `on_request` wrapped
functions:

```Rust
Response::new(401)
    .with_headers(vec![("WWW-Authenticate".to_string(), "Bearer realm=\"oauth2\"".to_string())])
    .with_body(r#"{ "error": "token was not present"}"#)
```

You can block or allow requests to reach the upstream service using a `Flow`. A `Flow` in an `enum`
value with two possible values:

- `Continue`: Defines an object that is forwarded to the response.

- `Break`: Aborts the request and returns the provided response.

Create a `Flow` as follows:

```Rust
async fn request_filter(request_state: RequestState) -> Flow<()> {
    let header_state = request_state.into_headers_state().await;
    let handler = header_state.handler();
    if handler.header("authorization").is_some() {
        Flow::Continue(())
    } else {
        Flow::Break(Response::new(401)
        .with_headers(vec![("WWW-Authenticate".to_string(), "Bearer realm=\"oauth2\"".to_string())])
        .with_body(r#"{ "error": "token was not present"}"#))
    }
}
```

> [!IMPORTANT] Due to the streaming nature of `proxy wasm`, it is possible for an early request to
> partially reach the upstream service while awaiting the `headers_state.into_body_state` function.
> Avoid this is by not awaiting the body. However, this is not possible for all policies. Configure
> your upstream to ignore partial requests if the policy must read the body.
>
> To avoid early responses reaching the client, see
> [Sharing Data Between Requests and Responses](https://docs.mulesoft.com/pdk/1.6/policies-pdk-configure-features-share-data).

## See Also

- [Implementing Your Custom Policy Features in Rust](https://docs.mulesoft.com/pdk/1.6/policies-pdk-configure-features)
