Commit d5e5f5f
authored
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
1 file changed
+1
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| 92 | + | |
92 | 93 | | |
93 | 94 | | |
94 | 95 | | |
| |||
0 commit comments