pub struct RelayService(/* private fields */);Available on crate feature
server only.Expand description
The hyper Service that serves the actual relay endpoints.
This service can be used standalone or embedded into an existing HTTP server.
Implementations§
Source§impl RelayService
impl RelayService
Sourcepub fn new(
handlers: Handlers,
headers: HeaderMap,
rate_limit: Option<ClientRateLimit>,
key_cache: KeyCache,
access: AccessConfig,
metrics: Arc<Metrics>,
) -> Self
pub fn new( handlers: Handlers, headers: HeaderMap, rate_limit: Option<ClientRateLimit>, key_cache: KeyCache, access: AccessConfig, metrics: Arc<Metrics>, ) -> Self
Creates a new RelayService.
This allows embedding the relay service into an existing HTTP server.
Sourcepub async fn handle_connection(
self,
stream: TcpStream,
tls_config: Option<TlsConfig>,
)
pub async fn handle_connection( self, stream: TcpStream, tls_config: Option<TlsConfig>, )
Handle the incoming connection.
If a tls_config is given, will serve the connection using HTTPS, otherwise HTTP.
§Example
// Create a relay service
let handlers = Handlers::default();
let headers = HeaderMap::new();
let key_cache = KeyCache::new(1024);
let metrics = Arc::new(Metrics::default());
let relay_service = RelayService::new(
handlers,
headers,
None, // No rate limiting
key_cache,
AccessConfig::Everyone,
metrics,
);
// Generate a self-signed certificate for HTTPS
let cert = rcgen::generate_simple_self_signed(vec!["localhost".to_string()])?;
let cert_der = cert.cert.der().to_vec();
let private_key_der = cert.signing_key.serialize_der();
let cert_chain = vec![CertificateDer::from(cert_der)];
let private_key = PrivateKeyDer::try_from(private_key_der)?;
// Serve with HTTPS
let server_config = Arc::new(
rustls::ServerConfig::builder()
.with_no_client_auth()
.with_single_cert(cert_chain, private_key)?,
);
let tls_config = TlsConfig::new(server_config);
relay_service
.clone()
.handle_connection(stream, Some(tls_config))
.await;
// Or serve with plain HTTP
relay_service.handle_connection(stream, None).await;Trait Implementations§
Source§impl Clone for RelayService
impl Clone for RelayService
Source§fn clone(&self) -> RelayService
fn clone(&self) -> RelayService
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for RelayService
impl Debug for RelayService
Source§impl Service<Request<Incoming>> for RelayService
impl Service<Request<Incoming>> for RelayService
Source§type Future = Pin<Box<dyn Future<Output = Result<<RelayService as Service<Request<Incoming>>>::Response, <RelayService as Service<Request<Incoming>>>::Error>> + Send>>
type Future = Pin<Box<dyn Future<Output = Result<<RelayService as Service<Request<Incoming>>>::Response, <RelayService as Service<Request<Incoming>>>::Error>> + Send>>
The future response value.
Auto Trait Implementations§
impl Freeze for RelayService
impl !RefUnwindSafe for RelayService
impl Send for RelayService
impl Sync for RelayService
impl Unpin for RelayService
impl !UnwindSafe for RelayService
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> CompatExt for T
impl<T> CompatExt for T
§impl<T, B1, B2> HttpService<B1> for T
impl<T, B1, B2> HttpService<B1> for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more