Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/a2a/extensions/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


HTTP_EXTENSION_HEADER = 'X-A2A-Extensions'
GRPC_EXTENSION_HEADER = 'x-a2a-extensions'


def get_requested_extensions(values: list[str]) -> set[str]:
Expand Down
6 changes: 3 additions & 3 deletions src/a2a/server/request_handlers/grpc_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from a2a import types
from a2a.auth.user import UnauthenticatedUser
from a2a.extensions.common import (
HTTP_EXTENSION_HEADER,
GRPC_EXTENSION_HEADER,
get_requested_extensions,
)
from a2a.grpc import a2a_pb2
Expand Down Expand Up @@ -76,7 +76,7 @@ def build(self, context: grpc.aio.ServicerContext) -> ServerCallContext:
user=user,
state=state,
requested_extensions=get_requested_extensions(
_get_metadata_value(context, HTTP_EXTENSION_HEADER)
_get_metadata_value(context, GRPC_EXTENSION_HEADER)
),
)

Expand Down Expand Up @@ -417,7 +417,7 @@ def _set_extension_metadata(
if server_context.activated_extensions:
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)

for e in sorted(server_context.activated_extensions)
]
)
22 changes: 11 additions & 11 deletions tests/server/request_handlers/test_grpc_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest

from a2a import types
from a2a.extensions.common import HTTP_EXTENSION_HEADER
from a2a.extensions.common import GRPC_EXTENSION_HEADER
from a2a.grpc import a2a_pb2
from a2a.server.context import ServerCallContext
from a2a.server.request_handlers import GrpcHandler, RequestHandler
Expand Down Expand Up @@ -350,8 +350,8 @@ async def test_send_message_with_extensions(
mock_grpc_context: AsyncMock,
) -> None:
mock_grpc_context.invocation_metadata.return_value = grpc.aio.Metadata(
(HTTP_EXTENSION_HEADER.lower(), 'foo'),
(HTTP_EXTENSION_HEADER.lower(), 'bar'),
(GRPC_EXTENSION_HEADER.lower(), 'foo'),
(GRPC_EXTENSION_HEADER.lower(), 'bar'),
Comment on lines +353 to +354
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'),

)

def side_effect(request, context: ServerCallContext):
Expand Down Expand Up @@ -379,8 +379,8 @@ def side_effect(request, context: ServerCallContext):
mock_grpc_context.set_trailing_metadata.call_args.args[0]
)
assert set(called_metadata) == {
(HTTP_EXTENSION_HEADER.lower(), 'foo'),
(HTTP_EXTENSION_HEADER.lower(), 'baz'),
(GRPC_EXTENSION_HEADER.lower(), 'foo'),
(GRPC_EXTENSION_HEADER.lower(), 'baz'),
Comment on lines +382 to +383
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'),

}

async def test_send_message_with_comma_separated_extensions(
Expand All @@ -390,8 +390,8 @@ async def test_send_message_with_comma_separated_extensions(
mock_grpc_context: AsyncMock,
) -> None:
mock_grpc_context.invocation_metadata.return_value = grpc.aio.Metadata(
(HTTP_EXTENSION_HEADER.lower(), 'foo ,, bar,'),
(HTTP_EXTENSION_HEADER.lower(), 'baz , bar'),
(GRPC_EXTENSION_HEADER.lower(), 'foo ,, bar,'),
(GRPC_EXTENSION_HEADER.lower(), 'baz , bar'),
Comment on lines +393 to +394
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'),

)
mock_request_handler.on_message_send.return_value = types.Message(
message_id='1',
Expand All @@ -415,8 +415,8 @@ async def test_send_streaming_message_with_extensions(
mock_grpc_context: AsyncMock,
) -> None:
mock_grpc_context.invocation_metadata.return_value = grpc.aio.Metadata(
(HTTP_EXTENSION_HEADER.lower(), 'foo'),
(HTTP_EXTENSION_HEADER.lower(), 'bar'),
(GRPC_EXTENSION_HEADER.lower(), 'foo'),
(GRPC_EXTENSION_HEADER.lower(), 'bar'),
Comment on lines +418 to +419
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'),

)

async def side_effect(request, context: ServerCallContext):
Expand Down Expand Up @@ -450,6 +450,6 @@ async def side_effect(request, context: ServerCallContext):
mock_grpc_context.set_trailing_metadata.call_args.args[0]
)
assert set(called_metadata) == {
(HTTP_EXTENSION_HEADER.lower(), 'foo'),
(HTTP_EXTENSION_HEADER.lower(), 'baz'),
(GRPC_EXTENSION_HEADER.lower(), 'foo'),
(GRPC_EXTENSION_HEADER.lower(), 'baz'),
Comment on lines +453 to +454
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'),

}
Loading