aws / aws/bedrock-agentcore-sdk-python

Processing Request Headers

Đang mở
#92 8 bình luận 1 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
761
Fork
147
Merge trung bình
1 ngày 23 giờ
Pull request đã merge (30 ngày)
7

Mô tả

**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)
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Bắt đầu bằng cách đọc các đường dẫn nội bộ _build_request_context và _handle_invocation, sau đó so sánh chúng với chữ ký _invoke_handler được đề xuất trong issue. Xác định các header của request đã được phân tích cú pháp và request.state hiện được biểu diễn như thế nào, cũng như context của handler được yêu cầu có phù hợp với framework hay không. Công việc được xem là hoàn tất khi có một phương án được maintainer phê duyệt, với hành vi rõ ràng và độ bao phủ cho các invocation handler.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
api, backend
Loại issue
Tính năng
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
28/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.