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§

source

type Extension: Extension

The extension produced by this provider if the negotiation was successful.

source

type Error: Error + Sync + Send + 'static

The error produced by this extension if the handshake failed.

Required Methods§

source

fn apply_headers(&self, headers: &mut HeaderMap)

Apply this extension’s headers to a request.

source

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.

source

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.

Implementations on Foreign Types§

source§

impl<'r, E> ExtensionProvider for &'r mut Ewhere E: ExtensionProvider,

§

type Extension = <E as ExtensionProvider>::Extension

§

type Error = <E as ExtensionProvider>::Error

source§

fn apply_headers(&self, headers: &mut HeaderMap)

source§

fn negotiate_client( &self, headers: &[Header<'_>] ) -> Result<Option<Self::Extension>, Self::Error>

source§

fn negotiate_server( &self, headers: &[Header<'_>] ) -> Result<Option<(Self::Extension, HeaderValue)>, Self::Error>

source§

impl<'r, E> ExtensionProvider for &'r Ewhere E: ExtensionProvider,

§

type Extension = <E as ExtensionProvider>::Extension

§

type Error = <E as ExtensionProvider>::Error

source§

fn apply_headers(&self, headers: &mut HeaderMap)

source§

fn negotiate_client( &self, headers: &[Header<'_>] ) -> Result<Option<Self::Extension>, Self::Error>

source§

fn negotiate_server( &self, headers: &[Header<'_>] ) -> Result<Option<(Self::Extension, HeaderValue)>, Self::Error>

Implementors§