pub struct GrpcProxy { /* private fields */ }Expand description
gRPC reverse proxy middleware.
Recognises requests with Content-Type: application/grpc* and forwards them
to a backend over HTTP/2, leaving all other requests to the next layer.
Requires the http2 Cargo feature.
§Example
use rust_web_server::app::App;
use rust_web_server::core::New;
use rust_web_server::proxy::GrpcProxy;
let app = App::new()
.wrap(GrpcProxy::new(["grpc-service:50051"]));Implementations§
Source§impl GrpcProxy
impl GrpcProxy
Sourcepub fn new<I, S>(backends: I) -> Self
pub fn new<I, S>(backends: I) -> Self
Create a proxy distributing gRPC connections across backends in round-robin order.
Each backend entry can be:
"host:port"— plain TCP (gRPC cleartext)"grpc://host:port"— plain TCP (explicit scheme)"grpcs://host:port"— TLS (gRPC over TLS; port defaults to 443)"https://host:port"— TLS (same asgrpcs://)
TLS backends require the http2 Cargo feature.
Sourcepub fn path_prefix(self, prefix: impl Into<String>) -> Self
pub fn path_prefix(self, prefix: impl Into<String>) -> Self
Only proxy requests whose URI starts with prefix; pass others through.
Trait Implementations§
Source§impl Middleware for GrpcProxy
Available on crate feature http2 only.
impl Middleware for GrpcProxy
Available on crate feature
http2 only.fn handle( &self, request: &Request, connection: &ConnectionInfo, next: &dyn Application, ) -> Result<Response, String>
Source§fn runs_inline(&self, _request: &Request, _connection: &ConnectionInfo) -> bool
fn runs_inline(&self, _request: &Request, _connection: &ConnectionInfo) -> bool
true when this layer’s own work for request never blocks (in-memory
state, atomics, short mutexes) — see Application::runs_inline. A
WithMiddleware stack runs inline only if every layer and the inner
application agree. Default false.Source§fn is_passthrough(
&self,
_request: &Request,
_connection: &ConnectionInfo,
) -> bool
fn is_passthrough( &self, _request: &Request, _connection: &ConnectionInfo, ) -> bool
true when handle would do nothing for request but call next
(e.g. a rate limit that isn’t configured). A WithMiddleware stack
offers the inner application’s execute_async only if every layer
passes the request through. Default false.Source§fn accepts_streamed_body(
&self,
_request: &Request,
_connection: &ConnectionInfo,
) -> bool
fn accepts_streamed_body( &self, _request: &Request, _connection: &ConnectionInfo, ) -> bool
true when this layer never reads request.body, so the inner
application may receive it as a stream (Application::streams_body).
A layer that inspects the body (CSRF tokens in a form, request
signatures, rewriting) must keep the default false: it would see an
empty body.Auto Trait Implementations§
impl !Freeze for GrpcProxy
impl !RefUnwindSafe for GrpcProxy
impl !UnwindSafe for GrpcProxy
impl Send for GrpcProxy
impl Sync for GrpcProxy
impl Unpin for GrpcProxy
impl UnsafeUnpin for GrpcProxy
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
Mutably borrows from an owned value. Read more