pub trait Extension: Debug {
    // Required methods
    fn is_enabled(&self) -> bool;
    fn name(&self) -> &str;
    fn params(&self) -> &[Param<'_>];
    fn configure(&mut self, params: &[Param<'_>]) -> Result<(), BoxedError>;
    fn encode(
        &mut self,
        header: &mut Header,
        data: &mut Storage<'_>
    ) -> Result<(), BoxedError>;
    fn decode(
        &mut self,
        header: &mut Header,
        data: &mut Vec<u8>
    ) -> Result<(), BoxedError>;

    // Provided method
    fn reserved_bits(&self) -> (bool, bool, bool) { ... }
}
Expand description

A websocket extension as per RFC 6455, section 9.

Extensions are invoked during handshake and subsequently during base frame encoding and decoding. The invocation during handshake differs on client and server side.

Server

  1. All extensions should consider themselves as disabled but available.
  2. When receiving a handshake request from a client, for each extension with a matching name, Extension::configure will be applied to the request parameters. The extension may internally enable itself.
  3. When sending back the response, for each extension whose Extension::is_enabled returns true, the extension name and its parameters (as returned by Extension::params) will be included in the response.

Client

  1. All extensions should consider themselves as disabled but available.
  2. When creating the handshake request, all extensions and its parameters (as returned by Extension::params) will be included in the request.
  3. When receiving the response from the server, for every extension with a matching name in the response, Extension::configure will be applied to the response parameters. The extension may internally enable itself.

After this handshake phase, extensions have been configured and are potentially enabled. Enabled extensions can then be used for further base frame processing.

Required Methods§

source

fn is_enabled(&self) -> bool

Is this extension enabled?

source

fn name(&self) -> &str

The name of this extension.

source

fn params(&self) -> &[Param<'_>]

The parameters this extension wants to send for negotiation.

source

fn configure(&mut self, params: &[Param<'_>]) -> Result<(), BoxedError>

Configure this extension with the parameters received from negotiation.

source

fn encode( &mut self, header: &mut Header, data: &mut Storage<'_> ) -> Result<(), BoxedError>

Encode a frame, given as frame header and payload data.

source

fn decode( &mut self, header: &mut Header, data: &mut Vec<u8> ) -> Result<(), BoxedError>

Decode a frame.

The frame header is given, as well as the accumulated payload data, i.e. the concatenated payload data of all message fragments.

Provided Methods§

source

fn reserved_bits(&self) -> (bool, bool, bool)

The reserved bits this extension uses.

Implementations on Foreign Types§

source§

impl<E: Extension + ?Sized> Extension for Box<E>

source§

fn is_enabled(&self) -> bool

source§

fn name(&self) -> &str

source§

fn params(&self) -> &[Param<'_>]

source§

fn configure(&mut self, params: &[Param<'_>]) -> Result<(), BoxedError>

source§

fn encode( &mut self, header: &mut Header, data: &mut Storage<'_> ) -> Result<(), BoxedError>

source§

fn decode( &mut self, header: &mut Header, data: &mut Vec<u8> ) -> Result<(), BoxedError>

source§

fn reserved_bits(&self) -> (bool, bool, bool)

Implementors§