feat(statusx): expose error metadata via x-status-metadata response header#593
Merged
Conversation
…eader vproto.ValidationError has no metadata field, so metadata set via statusx.WithMetadata would be lost on the vproto HTTP error path (unlike the connect path, which carries it natively in error details). Expose it out-of-band on the x-status-metadata response header: a JSON-encoded, URL-escaped map[string]string, set only when the error carries metadata. Add var ExposedHeaders (symmetric to AllowHeaders) so downstreams using the vproto path can wire the header into their CORS ExposedHeaders. The header ownership stays in statusx; httpx is left unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
molon
approved these changes
Jun 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
On the vproto HTTP error path, error metadata set via
statusx.WithMetadatawas being dropped, becausevproto.ValidationErrorhas no metadata field. This exposes it out-of-band on a response header.x-status-metadata(JSON-encoded, URL-escapedmap[string]string) on the response, only when the error actually carries metadata.var ExposedHeaders(symmetric to the existingvar AllowHeaders) so downstreams using the vproto path can concat it into their CORSExposedHeaders.Why this lives in statusx, not httpx
The connect protocol path already carries metadata natively in the error details (see
ConvertToConnectError), so it needs no header. Only the vproto path needs this workaround, because its message schema lacks the field.That means it would be wrong to wire the header into
httpx.Security(the generic CORS middleware) — a service that doesn't use vproto would get anx-status-metadataheader exposed that it never sets. The header is part of statusx's error protocol, so its ownership and itsExposedHeadersdeclaration stay in statusx.httpxis left untouched. Downstreams that use the vproto path opt in by addingstatusx.ExposedHeadersto their CORS config.Test
TestWriteVProtoHTTPError_MetadataHeader: header is set with the correct encoding when metadata is present, and omitted when absent.🤖 Generated with Claude Code