pub struct Config { /* private fields */ }
Expand description
A Configuration builder for grpc_web services.
Config
can be used to tweak the behavior of tonic_web services. Currently,
Config
instances only expose cors settings. However, since tonic_web is designed to work
with grpc-web compliant clients only, some cors options have specific default values and not
all settings are configurable.
Default values and configuration options
allow-origin
: All origins allowed by default. Configurable, but null and wildcard origins are not supported.allow-methods
:[POST,OPTIONS]
. Not configurable.allow-headers
: Set to whatever theOPTIONS
request carries. Not configurable.allow-credentials
:true
. Configurable.max-age
:86400
. Configurable.expose-headers
:grpc-status,grpc-message
. Configurable but values can only be added.grpc-status
andgrpc-message
will always be exposed.
Implementations
sourceimpl Config
impl Config
sourcepub fn allow_all_origins(self) -> Config
pub fn allow_all_origins(self) -> Config
Allow any origin to access this resource.
This is the default value.
sourcepub fn allow_origins<I>(self, origins: I) -> Config where
I: IntoIterator,
HeaderValue: TryFrom<I::Item>,
pub fn allow_origins<I>(self, origins: I) -> Config where
I: IntoIterator,
HeaderValue: TryFrom<I::Item>,
Only allow a specific set of origins to access this resource.
Example
tonic_web::config().allow_origins(vec!["http://a.com", "http://b.com"]);
sourcepub fn expose_headers<I>(self, headers: I) -> Config where
I: IntoIterator,
HeaderName: TryFrom<I::Item>,
pub fn expose_headers<I>(self, headers: I) -> Config where
I: IntoIterator,
HeaderName: TryFrom<I::Item>,
Adds multiple headers to the list of exposed headers.
Default: grpc-status,grpc-message
. These will always be included.
sourcepub fn max_age<T: Into<Option<Duration>>>(self, max_age: T) -> Config
pub fn max_age<T: Into<Option<Duration>>>(self, max_age: T) -> Config
Defines the maximum cache lifetime for operations allowed on this resource.
Default: “86400” (24 hours)
sourcepub fn allow_credentials(self, allow_credentials: bool) -> Config
pub fn allow_credentials(self, allow_credentials: bool) -> Config
If true, the access-control-allow-credentials
will be sent.
Default: true
sourcepub fn enable<S>(&self, service: S) -> GrpcWeb<S> where
S: Service<Request<Body>, Response = Response<BoxBody>>,
S: NamedService + Clone + Send + 'static,
S::Future: Send + 'static,
S::Error: Into<Box<dyn Error + Send + Sync>> + Send,
pub fn enable<S>(&self, service: S) -> GrpcWeb<S> where
S: Service<Request<Body>, Response = Response<BoxBody>>,
S: NamedService + Clone + Send + 'static,
S::Future: Send + 'static,
S::Error: Into<Box<dyn Error + Send + Sync>> + Send,
enable a tonic service to handle grpc-web requests with this configuration values.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnwindSafe for Config
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
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>
Wrap the input message T
in a tonic::Request
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more