---
schema_version: "1"
id: 134417694180f043b47b9a6eb380b7d4c7386a2e1b94a12b6bb145c88f6ecc82
title: 要求実行の停止
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/pdk/1.3/policies-pdk-configure-features-stop.md
canonical_url: https://docs.mulesoft.com/jp/pdk/1.3/policies-pdk-configure-features-stop
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 88d4c7b3948440286b576d7879c29a9433a7f16cd4bd2237491f9e096ee2768e
description: MuleSoft Documentation Site
release: "1.3"
latest: false
---
# 要求実行の停止

要求を捕捉して停止するには、ラップされる関数の ​`on_request`​ から ​`Response`​ オブジェクトを返します。

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

`フロー`​を使用して、アップストリームサービスへの要求の到達をブロックまたは許可できます。​`フロー`​は、次の 2 つの可能な値を持つ​`列挙型`​の値です。

- `Continue`​: 応答に転送されるオブジェクトを定義します。
- `Break`​: 要求を中止し、指定された応答を返します。

`フロー`​は次のように作成します。

```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"}"#))
    }
}
```

<table>
<tbody><tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
<div class="paragraph">
<p><code>proxy wasm</code>​ のストリーミングの性質により、​<code>headers_state.into_body_state</code>​ 関数を待っている間に、要求の一部がアップストリームサービスに早期に到達する可能性があります。これを避けるには、ボディの読み取りを待たないことです。しかし、この方法はすべてのポリシーで可能であるとは限りません。ポリシーがボディを読み取る必要がある場合は、部分的な要求を無視するようにアップストリームを設定してください。</p>
</div>
<div class="paragraph">
<p>応答がクライアントに早期に返されないようにするには、<a href="https://docs.mulesoft.com/jp/pdk/1.3/policies-pdk-configure-features-share-data" class="xref page">要求と応答でのデータの共有</a>を参照してください。</p>
</div>
</td>
</tr>
</tbody></table>

## [](#関連情報)関連情報

- [Rust でのカスタムポリシー機能の実装](https://docs.mulesoft.com/jp/pdk/1.3/policies-pdk-configure-features)