---
schema_version: "1"
id: 2366a086eae1b04e971a7d7a22439d1ab8444a0a8b5375b60172c44370d2937f
title: 要求実行の停止
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/pdk/1.4/policies-pdk-configure-features-stop.md
canonical_url: https://docs.mulesoft.com/jp/pdk/1.4/policies-pdk-configure-features-stop
source_site: docs.mulesoft.com
content_type: documentation
content_hash: fe780bb242f61953b667b5d3089005acfced0575572d7a45938d6067384d5ad5
description: MuleSoft Documentation Site
release: "1.4"
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.4/policies-pdk-configure-features-share-data" class="xref page">要求と応答でのデータの共有</a>を参照してください。</p>
</div>
</td>
</tr>
</tbody></table>

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

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