---
schema_version: "1"
id: e832d584f31bbbadfceaf292096471d5d2d85200cea499dbd45247b5eb667c44
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-share-data.md
canonical_url: https://docs.mulesoft.com/jp/pdk/1.3/policies-pdk-configure-features-share-data
source_site: docs.mulesoft.com
content_type: documentation
content_hash: fe88ce41978667d27e53561ce52fc0512be52d71cfb5afca013fd9c884d57089
description: MuleSoft Documentation Site
release: "1.3"
latest: false
---
# 要求と応答でのデータの共有

Flex Gateway ポリシー開発キット (PDK) は、要求と応答の間でデータを受け渡すための ​`RequestData`​ 列挙型を提供しています。

要求関数と応答関数の間で状況を共有するには、要求関数が、応答関数に渡すデータパラメーターが格納された ​`Flow::Continue`​ 列挙型変数を返す必要があります。応答関数は、要求関数の最終状況と渡されたデータパラメーターを含む ​`RequestData`​ パラメーターを受け取る必要があります。

`RequestData`​ 列挙型に格納される最終状況は次のとおりです。

- `RequestData::Continue(data)`​: 要求関数は ​`Flow::Continue(data)`​ で終了しました。
- `RequestData::Break`​ : 要求関数は ​`Flow::Break`​ で終了しました。
- `RequestData::Cancel`​: 要求機能は​[キャンセル](https://docs.mulesoft.com/jp/pdk/1.3/policies-pdk-configure-features#flow-cancellation)​されました。

要求関数が ​`Flow::Continue`​ で終了し、アップストリームポリシーによってキャンセルされなかった場合、​`RequestData::Continue`​ 変数には要求関数によって送信された値が格納されます。

これを実装するには、[policy-pdk-configure-features-stop.adoc](#policy-pdk-configure-features-stop.adoc) で使用されている​`フロー`​の例にラップされる関数の ​`on_response`​ を追加します。

```Rust
async fn request_filter(state: RequestState) -> Flow<String> {
    let state = state.into_headers_state().await;
    let handler = state.handler();
    if handler.header("authorization").is_some() {
        Flow::Continue(state.path())
    } 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"}"#),
        )
    }
}

async fn response_filter(state: ResponseState, request_data: RequestData<String>) {
    // Handle only completed requests
    if let RequestData::Continue(path) = request_data else {
        return;
    };

    let state = state.into_headers_state().await;
    logger::info!("Path: {path}, Status: {}", state.status_code());
}
```

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

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