hackney_ws_proto (hackney v4.0.1)

View Source

Summary

Functions

Encode the key into the accept value for the Websocket handshake response.

Construct an unmasked Websocket frame.

Generate a key for the Websocket handshake request.

Return a frame tuple from parsed state and data.

Construct a masked Websocket frame.

Negotiate the permessage-deflate extension.

Negotiate the x-webkit-deflate-frame extension.

Parse and validate the Websocket frame header.

Validate the negotiated permessage-deflate extension.

Types

close_code/0

-type close_code() :: 1000..1003 | 1006..1011 | 3000..4999.

deflate_opts/0

-type deflate_opts() ::
          #{level => zlib:zlevel(),
            mem_level => zlib:zmemlevel(),
            strategy => zlib:zstrategy(),
            server_context_takeover => takeover | no_takeover,
            client_context_takeover => takeover | no_takeover,
            server_max_window_bits => 8..15,
            client_max_window_bits => 8..15}.

extensions/0

-type extensions() :: map().

frag_state/0

-type frag_state() :: undefined | {fin | nofin, text | binary, rsv()}.

frame/0

-type frame() ::
          close | ping | pong |
          {text | binary | close | ping | pong, iodata()} |
          {close, close_code(), iodata()} |
          {fragment, fin | nofin, text | binary | continuation, iodata()}.

frame_type/0

-type frame_type() :: fragment | text | binary | close | ping | pong.

mask_key/0

-type mask_key() :: undefined | 0..4294967295.

rsv/0

-type rsv() :: <<_:3>>.

utf8_state/0

-type utf8_state() :: 0..8 | undefined.

Functions

encode_key(Key)

-spec encode_key(binary()) -> binary().

Encode the key into the accept value for the Websocket handshake response.

frame(_, Extensions)

-spec frame(frame(), extensions()) -> iodata().

Construct an unmasked Websocket frame.

key()

-spec key() -> binary().

Generate a key for the Websocket handshake request.

make_frame(_, Payload, CloseCode, _)

-spec make_frame(frame_type(), binary(), close_code() | undefined, frag_state()) -> frame().

Return a frame tuple from parsed state and data.

masked_frame(_, Extensions)

-spec masked_frame(frame(), extensions()) -> iodata().

Construct a masked Websocket frame.

We use a mask key of 0 if there is no payload for close, ping and pong frames.

negotiate_permessage_deflate(Params, Exts, Opts)

-spec negotiate_permessage_deflate([binary() | {binary(), binary()}], Exts, deflate_opts()) ->
                                      ignore | {ok, iolist(), Exts}
                                      when Exts :: extensions().

Negotiate the permessage-deflate extension.

negotiate_x_webkit_deflate_frame(Params, Exts, Opts)

-spec negotiate_x_webkit_deflate_frame([binary() | {binary(), binary()}], Exts, deflate_opts()) ->
                                          ignore | {ok, binary(), Exts}
                                          when Exts :: extensions().

Negotiate the x-webkit-deflate-frame extension.

The implementation is very basic and none of the parameters are currently supported.

parse_header(Data, Extensions, FragState)

-spec parse_header(binary(), extensions(), frag_state()) ->
                      error | more |
                      {frame_type(), frag_state(), rsv(), non_neg_integer(), mask_key(), binary()}.

Parse and validate the Websocket frame header.

This function also updates the fragmentation state according to information found in the frame's header.

parse_payload(Data, MaskKey, Utf8State, ParsedLen, Type, Len, FragState, Exts, _)

-spec parse_payload(binary(),
                    mask_key(),
                    utf8_state(),
                    non_neg_integer(),
                    frame_type(),
                    non_neg_integer(),
                    frag_state(),
                    extensions(),
                    rsv()) ->
                       {ok, binary(), utf8_state(), binary()} |
                       {ok, close_code(), binary(), utf8_state(), binary()} |
                       {more, binary(), utf8_state()} |
                       {more, close_code(), binary(), utf8_state()} |
                       {error, badframe | badencoding | badsize}.

Parse and validate the frame's payload.

Validation is only required for text and close frames which feature a UTF-8 payload.

validate_permessage_deflate(Params, Extensions, Opts)

Validate the negotiated permessage-deflate extension.