feat: Add HTTP caching headers to Agent Card endpoint by kabir · Pull Request #761 · a2aproject/a2a-java · GitHub
Skip to content

feat: Add HTTP caching headers to Agent Card endpoint - #761

Merged
jmesnil merged 1 commit into
a2aproject:mainfrom
kabir:issue-749
Mar 26, 2026
Merged

jmesnil merged 1 commit into
a2aproject:mainfrom
kabir:issue-749

Conversation

@kabir

@kabir kabir commented Mar 17, 2026

Copy link
Copy Markdown
Collaborator

Implements A2A specification section 8.6 caching requirements:

  • Cache-Control header with configurable max-age
  • ETag header derived from Agent Card content hash
  • Last-Modified header with initialization timestamp

Implementation:

  • Created AgentCardCacheMetadata bean in server-common to compute and cache HTTP headers at initialization
  • Enhanced HTTPRestResponse to support additional headers via Map
  • Updated RestHandler and JSON-RPC A2AServerRoutes to include caching headers
  • Caching headers applied to both REST and JSON-RPC transports (gRPC out of scope per spec)

Configuration:

  • Max-age configurable via a2a.agent-card.cache.max-age (default: 3600 seconds)
  • ETag calculated as MD5 hash of serialized Agent Card JSON
  • Last-Modified set to bean initialization time in RFC 1123 format

Testing:

  • Added testAgentCardHeaders() to AbstractA2AServerTest
  • Validates all three caching headers are present and correctly formatted
  • gRPC test overrides to skip (HTTP-only requirement)

Fixes #749 🦕

@gemini-code-assist

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

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 effectively implements HTTP caching for the Agent Card endpoint by adding Cache-Control, ETag, and Last-Modified headers, as specified. The implementation is well-structured, introducing a dedicated AgentCardCacheMetadata bean to compute and cache these headers at startup. The changes are correctly propagated to both JSON-RPC and REST transports, and the new functionality is validated with a new test case.

I have one suggestion to improve the consistency of ETag generation across different environments. Otherwise, the changes look good.

Comment thread server-common/src/main/java/io/a2a/server/AgentCardCacheMetadata.java Outdated
@jmesnil

jmesnil commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

@kabir the CI failure looks genuine

@kabir

kabir commented Mar 18, 2026

Copy link
Copy Markdown
Collaborator Author

@jmesnil Yep, investigating

@kabir

kabir commented Mar 18, 2026

Copy link
Copy Markdown
Collaborator Author

/gemini review

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

Copy link
Copy Markdown
Contributor

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 effectively implements HTTP caching for the Agent Card endpoint as per the A2A specification. The changes are well-structured, introducing an AgentCardCacheMetadata bean to encapsulate the caching logic and cleanly integrating it into the REST and JSON-RPC layers. The tests are also comprehensive, including a new test for the caching headers and appropriate overrides for gRPC.

To improve robustness, I recommend failing fast during application startup in AgentCardCacheMetadata if required dependencies are missing, rather than causing a NullPointerException at runtime.

Overall, this is a great addition that improves performance and compliance with the specification.

Implements A2A specification section 8.6 caching requirements:
- Cache-Control header with configurable max-age (CARD-CACHE-001)
- ETag header derived from Agent Card content hash (CARD-CACHE-002)
- Last-Modified header with initialization timestamp (CARD-CACHE-003)

**Implementation:**
- Created AgentCardCacheMetadata bean in server-common to compute and cache HTTP headers at initialization
- Enhanced HTTPRestResponse to support additional headers via Map
- Updated RestHandler and JSON-RPC A2AServerRoutes to include caching headers
- Caching headers applied to both REST and JSON-RPC transports (gRPC out of scope per spec)

**Configuration:**
- Max-age configurable via `a2a.agent-card.cache.max-age` (default: 3600 seconds)
- ETag calculated as MD5 hash of serialized Agent Card JSON
- Last-Modified set to bean initialization time in RFC 1123 format

**Testing:**
- Added testAgentCardHeaders() to AbstractA2AServerTest
- Validates all three caching headers are present and correctly formatted
- gRPC test overrides to skip (HTTP-only requirement)

Fixes a2aproject#749

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@kabir

kabir commented Mar 18, 2026

Copy link
Copy Markdown
Collaborator Author

@jmesnil Should be fine now

@jmesnil
jmesnil merged commit 100bf86 into a2aproject:main Mar 26, 2026
11 checks passed
@jmesnil

jmesnil commented Mar 26, 2026

Copy link
Copy Markdown
Contributor

salaboy pushed a commit to salaboy/a2a-java that referenced this pull request Jun 19, 2026
Implements A2A specification section 8.6 caching requirements:
- Cache-Control header with configurable max-age
- ETag header derived from Agent Card content hash
- Last-Modified header with initialization timestamp

**Implementation:**
- Created AgentCardCacheMetadata bean in server-common to compute and
cache HTTP headers at initialization
- Enhanced HTTPRestResponse to support additional headers via Map
- Updated RestHandler and JSON-RPC A2AServerRoutes to include caching
headers
- Caching headers applied to both REST and JSON-RPC transports (gRPC out
of scope per spec)

**Configuration:**
- Max-age configurable via `a2a.agent-card.cache.max-age` (default: 3600
seconds)
- ETag calculated as MD5 hash of serialized Agent Card JSON
- Last-Modified set to bean initialization time in RFC 1123 format

**Testing:**
- Added testAgentCardHeaders() to AbstractA2AServerTest
- Validates all three caching headers are present and correctly
formatted
- gRPC test overrides to skip (HTTP-only requirement)

Fixes a2aproject#749 🦕

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
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.

[Bug]: Agent Card response missing Cache-Control and ETag caching headers

2 participants