Skip to content

fix: add extra grpc header which is all lower case#756

Open
timn wants to merge 1 commit intoa2aproject:mainfrom
timn:timn/grpc-metadata-header
Open

fix: add extra grpc header which is all lower case#756
timn wants to merge 1 commit intoa2aproject:mainfrom
timn:timn/grpc-metadata-header

Conversation

@timn
Copy link
Contributor

@timn timn commented Mar 3, 2026

According to https://httpwg.org/specs/rfc7540.html#HttpHeaders headers in HTTP/2 (grpc transport) must all be lower case. Thus, using A2A via grpc fails when using the HTTP header. Add specific all lowercase header for gRPC.

Description

Thank you for opening a Pull Request!
Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Follow the CONTRIBUTING Guide.
  • Make your Pull Request title in the https://www.conventionalcommits.org/ specification.
    • Important Prefixes for release-please:
      • fix: which represents bug fixes, and correlates to a SemVer 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 bash scripts/format.sh from the repository root to format)
  • Appropriate docs were updated (if necessary)

According to https://httpwg.org/specs/rfc7540.html#HttpHeaders headers
in HTTP/2 (grpc transport) must all be lower case. Thus, using A2A via
grpc fails when using the HTTP header. Add specific all lowercase header
for gRPC.
@timn timn requested a review from a team as a code owner March 3, 2026 13:12
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue where A2A communication via gRPC failed due to incorrect HTTP header casing. It introduces a dedicated lowercase header for gRPC extensions and updates the gRPC request handler and associated tests to utilize this new header, ensuring adherence to HTTP/2 specifications for gRPC transport.

Highlights

  • New gRPC Extension Header: Introduced GRPC_EXTENSION_HEADER in src/a2a/extensions/common.py to specifically handle gRPC header requirements, which mandate lowercase headers.
  • gRPC Handler Update: Modified src/a2a/server/request_handlers/grpc_handler.py to use the new GRPC_EXTENSION_HEADER for both retrieving and setting extension metadata, ensuring compliance with HTTP/2 specifications for gRPC.
  • Test Suite Alignment: Updated tests/server/request_handlers/test_grpc_handler.py to reflect the change, ensuring that tests for gRPC extension handling now correctly use GRPC_EXTENSION_HEADER.
Changelog
  • src/a2a/extensions/common.py
    • Added GRPC_EXTENSION_HEADER constant with a lowercase value.
  • src/a2a/server/request_handlers/grpc_handler.py
    • Updated import statement to use GRPC_EXTENSION_HEADER instead of HTTP_EXTENSION_HEADER.
    • Modified build method to retrieve requested extensions using GRPC_EXTENSION_HEADER.
    • Changed _set_extension_metadata to use GRPC_EXTENSION_HEADER for trailing metadata.
  • tests/server/request_handlers/test_grpc_handler.py
    • Updated import statement to use GRPC_EXTENSION_HEADER.
    • Modified test_send_message_with_extensions to use GRPC_EXTENSION_HEADER for invocation metadata.
    • Adjusted assertion in test_send_message_with_extensions to check for GRPC_EXTENSION_HEADER.
    • Updated test_send_message_with_comma_separated_extensions to use GRPC_EXTENSION_HEADER for invocation metadata.
    • Modified test_send_streaming_message_with_extensions to use GRPC_EXTENSION_HEADER for invocation metadata.
    • Adjusted assertion in test_send_streaming_message_with_extensions to check for GRPC_EXTENSION_HEADER.
Activity
  • The pull request was opened by timn to address an issue with gRPC header casing.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly addresses an issue with gRPC headers by introducing a new lowercase constant GRPC_EXTENSION_HEADER and using it in the gRPC handler, aligning with HTTP/2 specifications. The changes are logical and the accompanying test modifications ensure correctness. My feedback includes a few minor suggestions to remove redundant .lower() calls on the new constant, which is already defined in lowercase, to improve code clarity.

context.set_trailing_metadata(
[
(HTTP_EXTENSION_HEADER.lower(), e)
(GRPC_EXTENSION_HEADER.lower(), e)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

The GRPC_EXTENSION_HEADER constant is already in lowercase. The call to .lower() is redundant and can be removed for clarity.

Suggested change
(GRPC_EXTENSION_HEADER.lower(), e)
(GRPC_EXTENSION_HEADER, e)

Comment on lines +353 to +354
(GRPC_EXTENSION_HEADER.lower(), 'foo'),
(GRPC_EXTENSION_HEADER.lower(), 'bar'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

The GRPC_EXTENSION_HEADER constant is already in lowercase. The calls to .lower() are redundant and can be removed for clarity.

Suggested change
(GRPC_EXTENSION_HEADER.lower(), 'foo'),
(GRPC_EXTENSION_HEADER.lower(), 'bar'),
(GRPC_EXTENSION_HEADER, 'foo'),
(GRPC_EXTENSION_HEADER, 'bar'),

Comment on lines +382 to +383
(GRPC_EXTENSION_HEADER.lower(), 'foo'),
(GRPC_EXTENSION_HEADER.lower(), 'baz'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

The GRPC_EXTENSION_HEADER constant is already in lowercase. The calls to .lower() are redundant and can be removed for clarity.

Suggested change
(GRPC_EXTENSION_HEADER.lower(), 'foo'),
(GRPC_EXTENSION_HEADER.lower(), 'baz'),
(GRPC_EXTENSION_HEADER, 'foo'),
(GRPC_EXTENSION_HEADER, 'baz'),

Comment on lines +393 to +394
(GRPC_EXTENSION_HEADER.lower(), 'foo ,, bar,'),
(GRPC_EXTENSION_HEADER.lower(), 'baz , bar'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

The GRPC_EXTENSION_HEADER constant is already in lowercase. The calls to .lower() are redundant and can be removed for clarity.

Suggested change
(GRPC_EXTENSION_HEADER.lower(), 'foo ,, bar,'),
(GRPC_EXTENSION_HEADER.lower(), 'baz , bar'),
(GRPC_EXTENSION_HEADER, 'foo ,, bar,'),
(GRPC_EXTENSION_HEADER, 'baz , bar'),

Comment on lines +418 to +419
(GRPC_EXTENSION_HEADER.lower(), 'foo'),
(GRPC_EXTENSION_HEADER.lower(), 'bar'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

The GRPC_EXTENSION_HEADER constant is already in lowercase. The calls to .lower() are redundant and can be removed for clarity.

Suggested change
(GRPC_EXTENSION_HEADER.lower(), 'foo'),
(GRPC_EXTENSION_HEADER.lower(), 'bar'),
(GRPC_EXTENSION_HEADER, 'foo'),
(GRPC_EXTENSION_HEADER, 'bar'),

Comment on lines +453 to +454
(GRPC_EXTENSION_HEADER.lower(), 'foo'),
(GRPC_EXTENSION_HEADER.lower(), 'baz'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

The GRPC_EXTENSION_HEADER constant is already in lowercase. The calls to .lower() are redundant and can be removed for clarity.

Suggested change
(GRPC_EXTENSION_HEADER.lower(), 'foo'),
(GRPC_EXTENSION_HEADER.lower(), 'baz'),
(GRPC_EXTENSION_HEADER, 'foo'),
(GRPC_EXTENSION_HEADER, 'baz'),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant