Repository navigation
error: add ConnectError::into_http_response for short-circuiting layers - #111
Merged
Merged
Conversation
Tower layers wrapping ConnectRpcService (auth, rate limiting, validation) need to deny a request without dispatching it. They cannot reuse the service's internal protocol-aware error rendering, which is private, so they end up hand-rolling the Connect-unary JSON shape regardless of the inbound protocol. That works for Connect-unary clients but produces a transport error rather than a structured permission_denied/unauthenticated for gRPC, gRPC-Web, and Connect-streaming clients. ConnectError::into_http_response detects the protocol from the request headers via Protocol::detect and delegates to the existing internal helpers, so a layer can produce the same wire shape the service itself would. Falls back to Connect-unary JSON for unrecognized or absent Content-Type (Connect GET, non-RPC requests). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
All contributors have signed the CLA ✍️ ✅ |
iainmcgin
marked this pull request as ready for review
May 18, 2026 16:51
rpb-ant
approved these changes
May 18, 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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Why
Tower layers wrapping
ConnectRpcService— auth, rate limiting, validation — need to deny a request without dispatching it. They cannot reuse the service's internal protocol-aware error rendering (it's private), so today they hand-roll a Connect-unary JSON response regardless of the inbound protocol. Connect-unary clients are happy; gRPC, gRPC-Web, and Connect-streaming clients see a transport-level failure instead of a structuredpermission_denied/unauthenticatederror, because they expected an HTTP 200 with trailers / anEndStreamResponseenvelope.What
ConnectError::into_http_response(self, &http::HeaderMap) -> http::Response<ConnectRpcBody>detects the inbound protocol from the request headers via the (already public)Protocol::detectand delegates to the existing internal helpers —streaming_error_responsefor Connect streaming / gRPC / gRPC-Web,error_response_eitherfor Connect unary. Unrecognized or absentContent-Type(Connect GET, non-RPC traffic) falls back to Connect-unary JSON, the most universally parseable shape.Confidence
11 unit tests covering the dispatch matrix: Connect unary (proto + json + no-Content-Type + unknown Content-Type), Connect streaming (proto + json codec), gRPC (proto + json), gRPC-Web (binary + text mode), and Content-Type with parameters. Each asserts HTTP status, response
Content-Type, and the protocol-specific body shape (envelope flag bytes,grpc-statusheader, JSONcode/messagefields).cargo fmtclean,cargo clippy --all-targets -- -D warningsclean,cargo docintroduces no new warnings.🤖 Generated with Claude Code