Struct tonic::transport::Endpoint

source ·
pub struct Endpoint { /* private fields */ }
Available on crate features transport and channel only.
Expand description

Channel builder.

This struct is used to build and configure HTTP/2 channels.

Implementations§

source§

impl Endpoint

source

pub fn from_static(s: &'static str) -> Self

Convert an Endpoint from a static string.

§Panics

This function panics if the argument is an invalid URI.

Endpoint::from_static("https://example.com");
source

pub fn from_shared(s: impl Into<Bytes>) -> Result<Self, Error>

Convert an Endpoint from shared bytes.

Endpoint::from_shared("https://example.com".to_string());
source

pub fn user_agent<T>(self, user_agent: T) -> Result<Self, 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"
source

pub fn origin(self, origin: Uri) -> Self

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"
source

pub fn timeout(self, dur: Duration) -> Self

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.

source

pub fn connect_timeout(self, dur: Duration) -> Self

Apply a timeout to connecting to the uri.

Defaults to no timeout.

builder.connect_timeout(Duration::from_secs(5));
source

pub fn tcp_keepalive(self, tcp_keepalive: Option<Duration>) -> Self

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)

source

pub fn concurrency_limit(self, limit: usize) -> Self

Apply a concurrency limit to each request.

builder.concurrency_limit(256);
source

pub fn rate_limit(self, limit: u64, duration: Duration) -> Self

Apply a rate limit to each request.

builder.rate_limit(32, Duration::from_secs(1));
source

pub fn initial_stream_window_size(self, sz: impl Into<Option<u32>>) -> Self

Sets the SETTINGS_INITIAL_WINDOW_SIZE option for HTTP2 stream-level flow control.

Default is 65,535

source

pub fn initial_connection_window_size(self, sz: impl Into<Option<u32>>) -> Self

Sets the max connection-level flow control for HTTP2

Default is 65,535

source

pub fn buffer_size(self, sz: impl Into<Option<usize>>) -> Self

Sets the tower service default internal buffer size

Default is 1024

source

pub fn tls_config(self, tls_config: ClientTlsConfig) -> Result<Self, Error>

Available on crate feature tls only.

Configures TLS for the endpoint.

source

pub fn tcp_nodelay(self, enabled: bool) -> Self

Set the value of TCP_NODELAY option for accepted connections. Enabled by default.

source

pub fn http2_keep_alive_interval(self, interval: Duration) -> Self

Set http2 KEEP_ALIVE_INTERVAL. Uses hyper’s default otherwise.

source

pub fn keep_alive_timeout(self, duration: Duration) -> Self

Set http2 KEEP_ALIVE_TIMEOUT. Uses hyper’s default otherwise.

source

pub fn keep_alive_while_idle(self, enabled: bool) -> Self

Set http2 KEEP_ALIVE_WHILE_IDLE. Uses hyper’s default otherwise.

source

pub fn http2_adaptive_window(self, enabled: bool) -> Self

Sets whether to use an adaptive flow control. Uses hyper’s default otherwise.

source

pub fn executor<E>(self, executor: E) -> Self
where E: Executor<Pin<Box<dyn Future<Output = ()> + Send>>> + Send + Sync + 'static,

Sets the executor used to spawn async tasks.

Uses tokio::spawn by default.

source

pub async fn connect(&self) -> Result<Channel, Error>

Create a channel from this config.

source

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.

source

pub async fn connect_with_connector<C>( &self, connector: C ) -> Result<Channel, Error>
where C: MakeConnection<Uri> + Send + 'static, C::Connection: Unpin + Send + 'static, C::Future: Send + 'static, Box<dyn Error + Send + Sync>: From<C::Error> + Send + 'static,

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.

source

pub fn connect_with_connector_lazy<C>(&self, connector: C) -> Channel
where C: MakeConnection<Uri> + Send + 'static, C::Connection: Unpin + Send + 'static, C::Future: Send + 'static, Box<dyn Error + Send + Sync>: From<C::Error> + Send + 'static,

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.

source

pub fn uri(&self) -> &Uri

Get the endpoint uri.

let endpoint = Endpoint::from_static("https://example.com");

assert_eq!(endpoint.uri(), &Uri::from_static("https://example.com"));

Trait Implementations§

source§

impl Clone for Endpoint

source§

fn clone(&self) -> Endpoint

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Endpoint

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<Uri> for Endpoint

source§

fn from(uri: Uri) -> Self

Converts to this type from the input type.
source§

impl FromStr for Endpoint

§

type Err = Error

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl TryFrom<&'static str> for Endpoint

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(t: &'static str) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Bytes> for Endpoint

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(t: Bytes) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<String> for Endpoint

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(t: String) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoRequest<T> for T

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more