Trait ratchet_rs::ExtensionProvider
source · pub trait ExtensionProvider {
type Extension: Extension;
type Error: Error + Sync + Send + 'static;
// Required methods
fn apply_headers(&self, headers: &mut HeaderMap);
fn negotiate_client(
&self,
headers: &[Header<'_>],
) -> Result<Option<Self::Extension>, Self::Error>;
fn negotiate_server(
&self,
headers: &[Header<'_>],
) -> Result<Option<(Self::Extension, HeaderValue)>, Self::Error>;
}
Expand description
A trait for negotiating an extension during a WebSocket handshake.
Extension providers allow for a single configuration to be used to negotiate multiple peers.
Required Associated Types§
Required Methods§
sourcefn apply_headers(&self, headers: &mut HeaderMap)
fn apply_headers(&self, headers: &mut HeaderMap)
Apply this extension’s headers to a request.
sourcefn negotiate_client(
&self,
headers: &[Header<'_>],
) -> Result<Option<Self::Extension>, Self::Error>
fn negotiate_client( &self, headers: &[Header<'_>], ) -> Result<Option<Self::Extension>, Self::Error>
Negotiate the headers that the server responded with.
If it is possible to negotiate this extension, then this should return an initialised extension.
If it is not possible to negotiate an extension then this should return None
, not Err
.
An error should only be returned if the server responded with a malformatted header or a
value that was not expected.
Returning Err
from this will fail the connection with the reason being the error’s
to_string()
value.
sourcefn negotiate_server(
&self,
headers: &[Header<'_>],
) -> Result<Option<(Self::Extension, HeaderValue)>, Self::Error>
fn negotiate_server( &self, headers: &[Header<'_>], ) -> Result<Option<(Self::Extension, HeaderValue)>, Self::Error>
Negotiate the headers that a client has sent.
If it is possible to negotiate this extension, then this should return a pair containing an
initialised extension and a HeaderValue
to return to the client.
If it is not possible to negotiate an extension then this should return None
, not Err
.
An error should only be returned if the server responded with a malformatted header or a
value that was not expected.
Returning Err
from this will fail the connection with the reason being the error’s
to_string()
value.