tonic icon indicating copy to clipboard operation
tonic copied to clipboard

Add catchall for router

Open shutton opened this issue 5 years ago • 2 comments

Feature Request

Crates

tonic

Motivation

While trying to implement a gRPC proxy server (and blend it with locally-implemented services), I found that I was forced to use the NamedService trait and tie that "generic" service to a single service name due to how the router tests leading strings. Rather than using an empty string as the name for the service, I thought it might be useful to have a means to intercept all requests at the bottom of the routing stack in case you want to forward anything you can't handle locally to another server.

Proposal

The simplest means I found was to add add_catchall_service(). This likely requires you to implement a full tower service that's able to inspect the to perform the appropriate action (and return tonic-compatible replies).

Alternatives

A more elegant solution would be to support services that can accept or decline the request (i.e., provide their own route predicate).

shutton avatar Aug 12 '20 02:08 shutton

Sorry for the delay on this, I think this is a great idea but I want to refactor some of the transport so will consider this in the new version.

LucioFranco avatar Nov 27 '20 16:11 LucioFranco

Any news on this?

ghost avatar Oct 12 '21 20:10 ghost