diff --git a/tonic-reflection/src/server.rs b/tonic-reflection/src/server.rs index fb3452534..e97a951f4 100644 --- a/tonic-reflection/src/server.rs +++ b/tonic-reflection/src/server.rs @@ -53,6 +53,7 @@ pub struct Builder<'b> { include_reflection_service: bool, service_names: Vec, + use_all_service_names: bool, symbols: HashMap>, } @@ -65,6 +66,7 @@ impl<'b> Builder<'b> { include_reflection_service: true, service_names: Vec::new(), + use_all_service_names: true, symbols: HashMap::new(), } } @@ -94,6 +96,16 @@ impl<'b> Builder<'b> { self } + /// Advertise a fully-qualified gRPC service name. + /// + /// If not called, then all services present in the registered file descriptor sets + /// will be advertised. + pub fn with_service_name(mut self, name: impl Into) -> Self { + self.use_all_service_names = false; + self.service_names.push(name.into()); + self + } + /// Build a gRPC Reflection Service to be served via Tonic. pub fn build(mut self) -> Result, Error> { if self.include_reflection_service { @@ -156,7 +168,9 @@ impl<'b> Builder<'b> { for service in &fd.service { let service_name = extract_name(prefix, "service", service.name.as_ref())?; - self.service_names.push(service_name.clone()); + if self.use_all_service_names { + self.service_names.push(service_name.clone()); + } self.symbols.insert(service_name.clone(), fd.clone()); for method in &service.method {