aws / aws/bedrock-agentcore-sdk-python
Processing Request Headers
- 主要言語
- Python
- スター
- 761
- フォーク
- 147
- 平均マージ
- 1日 23時間
- マージ済み PR(30日)
- 7
説明
**Is your feature request related to a problem? Please describe.**
When handling invocation requests, I need a reliable mechanism to parse specific headers and pass them to the handler function. I have not found a recommended approach for achieving this within the current framework. While I can implement a Starlette middleware to populate `request.state`, this state is not accessible within my handler.
Could you please advise on the best practice for accomplishing this?
**Describe the solution you'd like**
I would like to have the ability to pass `request.state` (or a similar context containing parsed headers) directly to the handler function. I have included a relevant code snippet below to illustrate the change that would address this need.
**Describe alternatives you've considered**
- Overriding the internal `_build_request_context` method, although I am hesitant to do so since it is not intended for external use.
- Adding an additional route via `app.routes.append`, but this approach requires rewriting significant portions of the existing `_handle_invocation` logic, which is not ideal.
**Additional context**
Please see the code snippet below for reference:
```
async def _invoke_handler(self, handler, request_context, takes_context, payload):
try:
args = (payload, request_context) if takes_context else (payload,)
if asyncio.iscoroutinefunction(handler):
return await handler(*args)
else:
loop = asyncio.get_event_loop()
return await loop.run_in_executor(None, handler, *args)
```
コントリビューションガイド
調査の方向性
まず内部の _build_request_context と _handle_invocation のパスを読み、issue で提案されている _invoke_handler シグネチャと比較します。パース済みのリクエストヘッダーと request.state が現在どのように表現されているか、また要求された handler context が framework に適合するかを確認します。maintainer に承認されたアプローチがあり、invocation handlers に対する明確な動作とカバレッジが備わっていれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- api, backend
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 28/100