pub struct MultiplexService<A, B> { /* private fields */ }
Expand description
A Service
that multiplexes requests between two underlying REST-ful and gRPC services.
In some scenarios, it can be useful to expose gRPC services on the same existing REST-ful HTTP endpoints as gRPC defaults to using HTTP/2, and doing so allows the use of a single exposed endpoint/port, leading to reduced configuration and complexity.
This service takes two services – one for REST-ful requests and one for gRPC requests – and multiplexes incoming
requests between the two by inspecting the request headers, specifically the Content-Type
header. If the header
starts with application/grpc
, the request is assumed to be a gRPC request and is forwarded to the gRPC service.
Otherwise, the request is assumed to be a REST-ful request and is forwarded to the REST-ful service.
Implementations§
Source§impl<A, B> MultiplexService<A, B>
impl<A, B> MultiplexService<A, B>
Trait Implementations§
Source§impl<A, B> Clone for MultiplexService<A, B>
impl<A, B> Clone for MultiplexService<A, B>
Source§impl<A, B> Service<Request<Incoming>> for MultiplexService<A, B>where
A: Service<Request<Incoming>, Error = Infallible>,
A::Response: IntoResponse,
A::Future: Send + 'static,
B: Service<Request<Incoming>>,
B::Response: IntoResponse,
B::Future: Send + 'static,
impl<A, B> Service<Request<Incoming>> for MultiplexService<A, B>where
A: Service<Request<Incoming>, Error = Infallible>,
A::Response: IntoResponse,
A::Future: Send + 'static,
B: Service<Request<Incoming>>,
B::Response: IntoResponse,
B::Future: Send + 'static,
Source§type Future = Pin<Box<dyn Future<Output = Result<<MultiplexService<A, B> as Service<Request<Incoming>>>::Response, <MultiplexService<A, B> as Service<Request<Incoming>>>::Error>> + Send>>
type Future = Pin<Box<dyn Future<Output = Result<<MultiplexService<A, B> as Service<Request<Incoming>>>::Response, <MultiplexService<A, B> as Service<Request<Incoming>>>::Error>> + Send>>
Auto Trait Implementations§
impl<A, B> Freeze for MultiplexService<A, B>
impl<A, B> RefUnwindSafe for MultiplexService<A, B>where
A: RefUnwindSafe,
B: RefUnwindSafe,
impl<A, B> Send for MultiplexService<A, B>
impl<A, B> Sync for MultiplexService<A, B>
impl<A, B> Unpin for MultiplexService<A, B>
impl<A, B> UnwindSafe for MultiplexService<A, B>where
A: UnwindSafe,
B: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, ReqBody, ResBody> GrpcService<ReqBody> for T
impl<T, ReqBody, ResBody> GrpcService<ReqBody> for T
Source§type ResponseBody = ResBody
type ResponseBody = ResBody
Source§fn poll_ready(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<(), <T as GrpcService<ReqBody>>::Error>>
fn poll_ready( &mut self, cx: &mut Context<'_>, ) -> Poll<Result<(), <T as GrpcService<ReqBody>>::Error>>
Ready
when the service is able to process requests. Read moreSource§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<S, R> ServiceExt<R> for Swhere
S: Service<R>,
impl<S, R> ServiceExt<R> for Swhere
S: Service<R>,
Source§fn into_make_service(self) -> IntoMakeService<S>
fn into_make_service(self) -> IntoMakeService<S>
MakeService
, that is a Service
whose
response is another service. Read moreSource§fn into_make_service_with_connect_info<C>(
self,
) -> IntoMakeServiceWithConnectInfo<S, C>
fn into_make_service_with_connect_info<C>( self, ) -> IntoMakeServiceWithConnectInfo<S, C>
MakeService
, that will store C
’s
associated ConnectInfo
in a request extension such that ConnectInfo
can extract it. Read moreSource§fn handle_error<F, T>(self, f: F) -> HandleError<Self, F, T>
fn handle_error<F, T>(self, f: F) -> HandleError<Self, F, T>
HandleError
, that will handle errors
by converting them into responses. Read moreSource§impl<T, Request> ServiceExt<Request> for T
impl<T, Request> ServiceExt<Request> for T
Source§fn ready(&mut self) -> Ready<'_, Self, Request>where
Self: Sized,
fn ready(&mut self) -> Ready<'_, Self, Request>where
Self: Sized,
Source§fn ready_oneshot(self) -> ReadyOneshot<Self, Request>where
Self: Sized,
fn ready_oneshot(self) -> ReadyOneshot<Self, Request>where
Self: Sized,
Source§fn oneshot(self, req: Request) -> Oneshot<Self, Request>where
Self: Sized,
fn oneshot(self, req: Request) -> Oneshot<Self, Request>where
Self: Sized,
Service
, calling it with the provided request once it is ready.Source§fn and_then<F>(self, f: F) -> AndThen<Self, F>
fn and_then<F>(self, f: F) -> AndThen<Self, F>
poll_ready
method. Read moreSource§fn map_response<F, Response>(self, f: F) -> MapResponse<Self, F>
fn map_response<F, Response>(self, f: F) -> MapResponse<Self, F>
poll_ready
method. Read moreSource§fn map_err<F, Error>(self, f: F) -> MapErr<Self, F>
fn map_err<F, Error>(self, f: F) -> MapErr<Self, F>
poll_ready
method. Read moreSource§fn map_result<F, Response, Error>(self, f: F) -> MapResult<Self, F>
fn map_result<F, Response, Error>(self, f: F) -> MapResult<Self, F>
Result<Self::Response, Self::Error>
)
to a different value, regardless of whether the future succeeds or
fails. Read moreSource§fn map_request<F, NewRequest>(self, f: F) -> MapRequest<Self, F>
fn map_request<F, NewRequest>(self, f: F) -> MapRequest<Self, F>
Source§fn then<F, Response, Error, Fut>(self, f: F) -> Then<Self, F>
fn then<F, Response, Error, Fut>(self, f: F) -> Then<Self, F>
Source§fn map_future<F, Fut, Response, Error>(self, f: F) -> MapFuture<Self, F>
fn map_future<F, Fut, Response, Error>(self, f: F) -> MapFuture<Self, F>
Source§impl<T> Track for T
impl<T> Track for T
Source§fn track_allocations(self, token: AllocationGroupToken) -> Tracked<Self>
fn track_allocations(self, token: AllocationGroupToken) -> Tracked<Self>
Tracked
wrapper. Read moreSource§fn in_current_allocation_group(self) -> Tracked<Self>
fn in_current_allocation_group(self) -> Tracked<Self>
Tracked
wrapper. Read more