Repository navigation
response: add RequestContext::path() — the requested procedure path - #116
Merged
Merged
Conversation
Spec (#112) gives interceptors and span builders the resolved method's static metadata, but only when a generated FooServiceServer<T> resolved the route — Spec.procedure is &'static str, and the dynamic Router can't supply one because its keys are owned Strings. An interceptor that must label or gate every request (auth, rate limiting, tracing) has no way back to the request URI by the time it runs: handle_*_request consumes the http::Request before constructing RequestContext. The result is that Spec is the only source of the procedure name, and it isn't always there. RequestContext::path() carries the requested procedure path ("/package.Service/Method") unconditionally. It is the wire truth, set from the request URI at every dispatch site, with the leading slash to match Spec::procedure and connect-go's Spec.Procedure. spec() remains the source of richer static metadata (stream type, idempotency); path() is the always-present method name. The leading slash is reconstructed from the stripped path variable already in scope at each RequestContext::new site (the dispatch path strips it for Dispatcher::lookup keys); strip_prefix removes at most one leading slash so the round-trip is exact for any HTTP request that reached the dispatch layer. 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 19, 2026 00:38
iainmcgin
enabled auto-merge (squash)
May 19, 2026 00:39
kollektiv
approved these changes
May 19, 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
Spec(#112) gives interceptors and span builders the resolved method's static metadata, but only when a generatedFooServiceServer<T>dispatcher matched the route —Spec.procedureis&'static str, and the dynamicRoutercan't supply one because its keys are ownedStrings. By the time an interceptor (#114) runs,handle_*_requesthas already consumed thehttp::Request, so there is no way back to the request URI. An interceptor that must label or gate every request — an auth boundary, a span builder, a rate limiter — therefore has no reliable source for the method name on the dynamic-Routerpath.What
RequestContext::path()carries the requested procedure path (/package.Service/Method) unconditionally — populated at every dispatch site from the request URI. It is the wire truth;spec()remains the source of resolved static metadata (stream type, idempotency level). When both are present they're identical strings;path()exists for the cases wherespec()cannot be.Storage is
Option<String>(matchingspec()/protocol()),Noneonly for hand-built contexts. The leading slash matchesSpec::procedure, connect-go'sSpec.Procedure, andhttp::Uri::path().The five
RequestContext::new(...)call sites already have the stripped lookup-key form (pkg.Service/Method) in scope; the leading slash is reconstructed viaformat!("/{path}").strip_prefix('/')removes at most one leading slash, so the round-trip is exact for any HTTP request that reaches the dispatch layer.Confidence
request_context_with_path(response.rs) — builder round-trips,Nonefor hand-built contexts,Some("")preserved verbatim.path_flows_to_handler_context(service.rs) — dispatches a request to/svc/Methodthrough the dynamicRouterand asserts the handler seespath() == Some("/svc/Method")andspec() == None— the casepath()exists for.cargo test(306 pass),cargo fmt,cargo clippy --all-targets -- -D warnings,cargo docall clean.cargo check --all-featuresclean.Possible follow-ups (not blocking)
format!("/{path}"). They can be collapsed to one by capturing the un-stripped URI path first and slicing it for the lookup key, at the cost of restructuring borrow scopes. ~30-byte alloc per request is noise next to the body buffer andHeaderMapclone on the same path; worth it ifbenches/rpc/shows a difference.handle_unary_request; the gRPC-fast-path and streaming entry points use the sameformat!("/{path}")recipe but aren't independently covered.🤖 Generated with Claude Code