pub struct H2ReverseProxy { /* private fields */ }Expand description
Reverse proxy that forwards requests to HTTP/2 backends.
Wraps ReverseProxy and forces HTTP/2 (h2) for all upstream connections.
Requires the http2 Cargo feature.
This proxy also transparently handles gRPC traffic
(Content-Type: application/grpc*) — gRPC DATA frames are forwarded
as-is because gRPC is HTTP/2. Note that HTTP/2 trailers (used by gRPC for
grpc-status and grpc-message) are not yet propagated.
§Example
use rust_web_server::app::App;
use rust_web_server::core::New;
use rust_web_server::proxy::H2ReverseProxy;
let app = App::new()
.wrap(H2ReverseProxy::new(["grpc-service:9090"])
.path_prefix("/svc.MyService"));Implementations§
Source§impl H2ReverseProxy
impl H2ReverseProxy
Sourcepub fn new<I, S>(backends: I) -> Self
pub fn new<I, S>(backends: I) -> Self
Create a proxy distributing requests across backends in round-robin order.
Each entry must be "host:port" or "h2://host:port".
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.
Sourcepub fn connect_timeout_ms(self, ms: u64) -> Self
pub fn connect_timeout_ms(self, ms: u64) -> Self
Override the TCP connect timeout (default: 5 s).
Sourcepub fn read_timeout_ms(self, ms: u64) -> Self
pub fn read_timeout_ms(self, ms: u64) -> Self
Override the response read timeout (default: 30 s).
Trait Implementations§
Source§impl Middleware for H2ReverseProxy
Available on crate feature http2 only.
impl Middleware for H2ReverseProxy
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 H2ReverseProxy
impl RefUnwindSafe for H2ReverseProxy
impl Send for H2ReverseProxy
impl Sync for H2ReverseProxy
impl Unpin for H2ReverseProxy
impl UnsafeUnpin for H2ReverseProxy
impl UnwindSafe for H2ReverseProxy
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