Skip to content

Commit d5e5f5f

Browse files
feat: Add HTTP Headers to ServerCallContext for Improved Handler Access (#182)
# Description This PR enhances our A2A framework by adding HTTP headers to the `ServerCallContext`, making them accessible via `context.state['headers']`. The call context is a key component of our request-handling system, designed to provide handlers with request-specific information—like user details and additional state—in a structured, modular way. This abstraction keeps our handlers clean and decoupled from the raw HTTP request. **Why Add Headers to the Context?** * **Essential Metadata:** HTTP headers carry critical information, such as authentication tokens, content types, and custom parameters, that handlers often need to process requests correctly. Including headers in the context ensures this data is easily accessible. * **Architectural Consistency:** We already use the call context to pass request-specific data (e.g., `state['auth']`). Adding headers follows this established pattern, keeping our design cohesive. * **Better Developer Experience:** Without this change, accessing headers in handlers requires extra effort, like refactoring or passing the full request object. With headers in `context.state['headers']`, developers can work more efficiently and with fewer errors. **Addressing Concerns:** * **Performance:** Headers are small, and their inclusion in the per-request context has a negligible performance impact. * **Security:** Headers may include sensitive data (e.g., tokens), but the call context already handles similar information securely. Handlers should follow existing best practices for data handling. This change makes our framework more intuitive and developer-friendly. I encourage the team to merge this PR to improve handler efficiency and maintain a consistent, modular architecture. - [ ] Follow the [`CONTRIBUTING` Guide](https://github.com/google-a2a/a2a-python/blob/main/CONTRIBUTING.md). - [ ] Make your Pull Request title in the <https://www.conventionalcommits.org/> specification. - Important Prefixes for [release-please](https://github.com/googleapis/release-please): - `fix:` which represents bug fixes, and correlates to a [SemVer](https://semver.org/) patch. - `feat:` represents a new feature, and correlates to a SemVer minor. - `feat!:`, or `fix!:`, `refactor!:`, etc., which represent a breaking change (indicated by the `!`) and will result in a SemVer major. - [ ] Ensure the tests and linter pass (Run `nox -s format` from the repository root to format) - [ ] Appropriate docs were updated (if necessary)
1 parent 60168b7 commit d5e5f5f

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

src/a2a/server/apps/jsonrpc/jsonrpc_app.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def build(self, request: Request) -> ServerCallContext:
8989
with contextlib.suppress(Exception):
9090
user = StarletteUserProxy(request.user)
9191
state['auth'] = request.auth
92+
state['headers'] = dict(request.headers)
9293
return ServerCallContext(user=user, state=state)
9394

9495

0 commit comments

Comments
 (0)