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>
Auto Trait Implementations§
impl !Freeze for GrpcProxy
impl RefUnwindSafe for GrpcProxy
impl Send for GrpcProxy
impl Sync for GrpcProxy
impl Unpin for GrpcProxy
impl UnsafeUnpin for GrpcProxy
impl UnwindSafe 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