aws / aws/bedrock-agentcore-sdk-python
Processing Request Headers
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 764
- 派生
- 148
- 平均合并
- 1 天 23 小时
- 30 天内合并 PR
- 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_contextmethod, 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_invocationlogic, 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)
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先阅读内部的 _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