pub fn validate_version_metadata<S: BuildHasher>(
metadata: &HashMap<String, String, S>,
require: bool,
) -> Result<(), A2aError>Expand description
Validates the A2A version carried in a binding’s request metadata.
The counterpart of this crate’s private header validator, for bindings that carry service parameters in a string map rather than in HTTP headers, and the supported way for a binding outside this crate to enforce §3.6.2 — which the built-in bindings do through private helpers this makes public. Without it an out-of-tree binding can send a version but cannot check one, and would have to reimplement the comparison and hope it stays in step.
Key lookup is case-insensitive. Any 1.x is accepted and patch segments
are ignored, per §3.6. The map is generic over its hasher so a binding that
keeps metadata in something other than the default RandomState — most
transport crates do — can pass it without rebuilding the map.
require decides what an absent or empty value means, and the two answers
are both defensible, which is why it is the caller’s to make. §3.6.2 says a
missing value MUST be read as protocol 0.3 — a version this server does not
implement — so true rejects it, matching the reference Python SDK and this
crate’s own HTTP default. false accepts it, which is what the gRPC binding
does for clients predating the parameter.
§Errors
A2aError::version_not_supported when the version is one this server does
not implement, or is absent while require is set.
§Example
use a2a_protocol_server::dispatch::validate_version_metadata;
use std::collections::HashMap;
let mut metadata = HashMap::new();
metadata.insert("A2A-Version".to_string(), "1.0".to_string());
assert!(validate_version_metadata(&metadata, true).is_ok());
// Absent, and the caller requires it: rejected as 0.3 per §3.6.2.
assert!(validate_version_metadata(&HashMap::new(), true).is_err());