aws / aws/bedrock-agentcore-sdk-python
Processing Request Headers
- Vorherrschende Sprache
- Python
- Sterne
- 761
- Forks
- 147
- Ø Merge
- 1 T. 23 Std.
- Gemergte PRs (30 T.)
- 7
Beschreibung
**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)
```
Beitragsleitfaden
Rechercherichtung
Beginne damit, die internen Pfade _build_request_context und _handle_invocation zu lesen, und vergleiche sie anschließend mit der im Issue vorgeschlagenen _invoke_handler-Signatur. Ermittle, wie geparste Request-Header und request.state derzeit dargestellt werden und ob der angeforderte Handler-Kontext zum Framework passt. Als erledigt gilt dies, wenn ein von einem Maintainer genehmigter Ansatz mit eindeutigem Verhalten und Abdeckung für Invocation-Handler vorliegt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- api, backend
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 28/100