pub struct Endpoint { /* private fields */ }
Expand description
Channel builder.
This struct is used to build and configure HTTP/2 channels.
Implementations
sourceimpl Endpoint
impl Endpoint
sourcepub fn from_static(s: &'static str) -> Endpoint
pub fn from_static(s: &'static str) -> Endpoint
Convert an Endpoint
from a static string.
Panics
This function panics if the argument is an invalid URI.
Endpoint::from_static("https://example.com");
Convert an Endpoint
from shared bytes.
Endpoint::from_shared("https://example.com".to_string());
sourcepub fn user_agent<T>(self, user_agent: T) -> Result<Endpoint, Error>where
T: TryInto<HeaderValue>,
pub fn user_agent<T>(self, user_agent: T) -> Result<Endpoint, Error>where
T: TryInto<HeaderValue>,
Set a custom user-agent header.
user_agent
will be prepended to Tonic’s default user-agent string (tonic/x.x.x
).
It must be a value that can be converted into a valid http::HeaderValue
or building
the endpoint will fail.
builder.user_agent("Greeter").expect("Greeter should be a valid header value");
// user-agent: "Greeter tonic/x.x.x"
sourcepub fn origin(self, origin: Uri) -> Endpoint
pub fn origin(self, origin: Uri) -> Endpoint
Set a custom origin.
Override the origin
, mainly useful when you are reaching a Server/LoadBalancer
which serves multiple services at the same time.
It will play the role of SNI (Server Name Indication).
builder.origin("https://example.com".parse().expect("http://example.com must be a valid URI"));
// origin: "https://example.com"
sourcepub fn timeout(self, dur: Duration) -> Endpoint
pub fn timeout(self, dur: Duration) -> Endpoint
Apply a timeout to each request.
builder.timeout(Duration::from_secs(5));
Notes
This does not set the timeout metadata (grpc-timeout
header) on
the request, meaning the server will not be informed of this timeout,
for that use Request::set_timeout
.
sourcepub fn connect_timeout(self, dur: Duration) -> Endpoint
pub fn connect_timeout(self, dur: Duration) -> Endpoint
Apply a timeout to connecting to the uri.
Defaults to no timeout.
builder.connect_timeout(Duration::from_secs(5));
sourcepub fn tcp_keepalive(self, tcp_keepalive: Option<Duration>) -> Endpoint
pub fn tcp_keepalive(self, tcp_keepalive: Option<Duration>) -> Endpoint
Set whether TCP keepalive messages are enabled on accepted connections.
If None
is specified, keepalive is disabled, otherwise the duration
specified will be the time to remain idle before sending TCP keepalive
probes.
Default is no keepalive (None
)
sourcepub fn concurrency_limit(self, limit: usize) -> Endpoint
pub fn concurrency_limit(self, limit: usize) -> Endpoint
Apply a concurrency limit to each request.
builder.concurrency_limit(256);
sourcepub fn rate_limit(self, limit: u64, duration: Duration) -> Endpoint
pub fn rate_limit(self, limit: u64, duration: Duration) -> Endpoint
Apply a rate limit to each request.
builder.rate_limit(32, Duration::from_secs(1));
sourcepub fn initial_stream_window_size(self, sz: impl Into<Option<u32>>) -> Endpoint
pub fn initial_stream_window_size(self, sz: impl Into<Option<u32>>) -> Endpoint
Sets the SETTINGS_INITIAL_WINDOW_SIZE
option for HTTP2
stream-level flow control.
Default is 65,535
sourcepub fn initial_connection_window_size(
self,
sz: impl Into<Option<u32>>
) -> Endpoint
pub fn initial_connection_window_size(
self,
sz: impl Into<Option<u32>>
) -> Endpoint
Sets the max connection-level flow control for HTTP2
Default is 65,535
sourcepub fn tls_config(self, tls_config: ClientTlsConfig) -> Result<Endpoint, Error>
pub fn tls_config(self, tls_config: ClientTlsConfig) -> Result<Endpoint, Error>
Configures TLS for the endpoint.
sourcepub fn tcp_nodelay(self, enabled: bool) -> Endpoint
pub fn tcp_nodelay(self, enabled: bool) -> Endpoint
Set the value of TCP_NODELAY
option for accepted connections. Enabled by default.
sourcepub fn http2_keep_alive_interval(self, interval: Duration) -> Endpoint
pub fn http2_keep_alive_interval(self, interval: Duration) -> Endpoint
Set http2 KEEP_ALIVE_INTERVAL. Uses hyper
’s default otherwise.
sourcepub fn keep_alive_timeout(self, duration: Duration) -> Endpoint
pub fn keep_alive_timeout(self, duration: Duration) -> Endpoint
Set http2 KEEP_ALIVE_TIMEOUT. Uses hyper
’s default otherwise.
sourcepub fn keep_alive_while_idle(self, enabled: bool) -> Endpoint
pub fn keep_alive_while_idle(self, enabled: bool) -> Endpoint
Set http2 KEEP_ALIVE_WHILE_IDLE. Uses hyper
’s default otherwise.
sourcepub fn http2_adaptive_window(self, enabled: bool) -> Endpoint
pub fn http2_adaptive_window(self, enabled: bool) -> Endpoint
Sets whether to use an adaptive flow control. Uses hyper
’s default otherwise.
sourcepub fn executor<E>(self, executor: E) -> Endpointwhere
E: 'static + Executor<Pin<Box<dyn Future<Output = ()> + Send + 'static, Global>>> + Send + Sync,
pub fn executor<E>(self, executor: E) -> Endpointwhere
E: 'static + Executor<Pin<Box<dyn Future<Output = ()> + Send + 'static, Global>>> + Send + Sync,
Sets the executor used to spawn async tasks.
Uses tokio::spawn
by default.
sourcepub async fn connect(&self) -> impl Future<Output = Result<Channel, Error>>
pub async fn connect(&self) -> impl Future<Output = Result<Channel, Error>>
Create a channel from this config.
sourcepub fn connect_lazy(&self) -> Channel
pub fn connect_lazy(&self) -> Channel
Create a channel from this config.
The channel returned by this method does not attempt to connect to the endpoint until first use.
sourcepub async fn connect_with_connector<C>(
&self,
connector: C
) -> impl Future<Output = Result<Channel, Error>>where
C: 'static + MakeConnection<Uri> + Send,
<C as MakeConnection<Uri>>::Connection: 'static + Unpin + Send,
<C as MakeConnection<Uri>>::Future: 'static + Send,
Box<dyn Error + Sync + Send + 'static, Global>: 'static + From<<C as MakeConnection<Uri>>::Error> + Send,
pub async fn connect_with_connector<C>(
&self,
connector: C
) -> impl Future<Output = Result<Channel, Error>>where
C: 'static + MakeConnection<Uri> + Send,
<C as MakeConnection<Uri>>::Connection: 'static + Unpin + Send,
<C as MakeConnection<Uri>>::Future: 'static + Send,
Box<dyn Error + Sync + Send + 'static, Global>: 'static + From<<C as MakeConnection<Uri>>::Error> + Send,
Connect with a custom connector.
This allows you to build a Channel that uses a non-HTTP transport.
See the uds
example for an example on how to use this function to build channel that
uses a Unix socket transport.
The connect_timeout
will still be applied.
sourcepub fn connect_with_connector_lazy<C>(&self, connector: C) -> Channelwhere
C: 'static + MakeConnection<Uri> + Send,
<C as MakeConnection<Uri>>::Connection: 'static + Unpin + Send,
<C as MakeConnection<Uri>>::Future: 'static + Send,
Box<dyn Error + Sync + Send + 'static, Global>: 'static + From<<C as MakeConnection<Uri>>::Error> + Send,
pub fn connect_with_connector_lazy<C>(&self, connector: C) -> Channelwhere
C: 'static + MakeConnection<Uri> + Send,
<C as MakeConnection<Uri>>::Connection: 'static + Unpin + Send,
<C as MakeConnection<Uri>>::Future: 'static + Send,
Box<dyn Error + Sync + Send + 'static, Global>: 'static + From<<C as MakeConnection<Uri>>::Error> + Send,
Connect with a custom connector lazily.
This allows you to build a Channel that uses a non-HTTP transport connect to it lazily.
See the uds
example for an example on how to use this function to build channel that
uses a Unix socket transport.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Endpoint
impl Send for Endpoint
impl Sync for Endpoint
impl Unpin for Endpoint
impl !UnwindSafe for Endpoint
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
sourcefn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request