hackney_cow_http2_machine (hackney v3.0.1)

View Source

Summary

Types

continued_frame/0

headers/0

-type headers() :: [{binary(), iodata()}].

http2_machine/0

-type http2_machine() ::
          #http2_machine{mode :: client | server,
                         opts :: opts(),
                         state ::
                             settings | normal |
                             {continuation,
                              request | response | trailers | push_promise,
                              continued_frame()},
                         preface_timer :: undefined | reference(),
                         settings_timer :: undefined | reference(),
                         local_settings :: map(),
                         next_settings :: undefined | map(),
                         remote_settings :: map(),
                         local_window :: integer(),
                         remote_window :: integer(),
                         local_streamid :: pos_integer(),
                         remote_streamid :: non_neg_integer(),
                         last_remote_streamid :: non_neg_integer(),
                         streams :: #{hackney_cow_http2:streamid() => stream()},
                         local_lingering_streams :: [hackney_cow_http2:streamid()],
                         remote_lingering_streams :: [hackney_cow_http2:streamid()],
                         decode_state :: hackney_cow_hpack:state(),
                         encode_state :: hackney_cow_hpack:state()}.

opts/0

-type opts() ::
          #{connection_window_margin_size => 0..2147483647,
            connection_window_update_threshold => 0..2147483647,
            enable_connect_protocol => boolean(),
            initial_connection_window_size => 65535..2147483647,
            initial_stream_window_size => 0..2147483647,
            max_connection_window_size => 0..2147483647,
            max_concurrent_streams => non_neg_integer() | infinity,
            max_decode_table_size => non_neg_integer(),
            max_encode_table_size => non_neg_integer(),
            max_fragmented_header_block_size => 16384..2147483647,
            max_frame_size_received => 16384..16777215,
            max_frame_size_sent => 16384..16777215 | infinity,
            max_stream_window_size => 0..2147483647,
            message_tag => any(),
            preface_timeout => timeout(),
            settings_timeout => timeout(),
            stream_window_data_threshold => 0..2147483647,
            stream_window_margin_size => 0..2147483647,
            stream_window_update_threshold => 0..2147483647}.

pseudo_headers/0

-type pseudo_headers() ::
          #{} |
          #{status := status()} |
          #{method := binary(), authority := binary()} |
          #{method := binary(),
            scheme := binary(),
            authority := binary(),
            path := binary(),
            protocol => binary()}.

status/0

-type status() :: 100..999.

stream/0

-type stream() ::
          #stream{id :: hackney_cow_http2:streamid(),
                  method :: binary(),
                  local :: idle | hackney_cow_http2:fin(),
                  local_window :: integer(),
                  local_buffer ::
                      queue:queue({hackney_cow_http2:fin(),
                                   non_neg_integer(),
                                   {data, iodata()} |
                                   #sendfile{offset :: non_neg_integer(),
                                             bytes :: pos_integer(),
                                             path :: file:name_all()}}),
                  local_buffer_size :: non_neg_integer(),
                  local_trailers :: undefined | headers(),
                  remote :: idle | hackney_cow_http2:fin(),
                  remote_window :: integer(),
                  remote_expected_size :: undefined | non_neg_integer(),
                  remote_read_size :: non_neg_integer(),
                  te :: undefined | binary()}.

Functions

ensure_window(Size, State)

-spec ensure_window(non_neg_integer(), State) -> ok | {ok, pos_integer(), State}
                       when State :: http2_machine().

ensure_window(StreamID, Size, State)

-spec ensure_window(hackney_cow_http2:streamid(), non_neg_integer(), State) ->
                       ok | {ok, pos_integer(), State}
                       when State :: http2_machine().

frame(Frame, State)

-spec frame(hackney_cow_http2:frame(), State) ->
               {ok, State} |
               {ok, {data, hackney_cow_http2:streamid(), hackney_cow_http2:fin(), binary()}, State} |
               {ok,
                {headers,
                 hackney_cow_http2:streamid(),
                 hackney_cow_http2:fin(),
                 headers(),
                 pseudo_headers(),
                 non_neg_integer() | undefined},
                State} |
               {ok, {trailers, hackney_cow_http2:streamid(), headers()}, State} |
               {ok, {rst_stream, hackney_cow_http2:streamid(), hackney_cow_http2:error()}, State} |
               {ok,
                {push_promise,
                 hackney_cow_http2:streamid(),
                 hackney_cow_http2:streamid(),
                 headers(),
                 pseudo_headers()},
                State} |
               {ok, {goaway, hackney_cow_http2:streamid(), hackney_cow_http2:error(), binary()}, State} |
               {send,
                [{hackney_cow_http2:streamid(),
                  hackney_cow_http2:fin(),
                  [{data, iodata()} |
                   #sendfile{offset :: non_neg_integer(),
                             bytes :: pos_integer(),
                             path :: file:name_all()} |
                   {trailers, headers()}]}],
                State} |
               {error,
                {stream_error, hackney_cow_http2:streamid(), hackney_cow_http2:error(), atom()},
                State} |
               {error, {connection_error, hackney_cow_http2:error(), atom()}, State}
               when State :: http2_machine().

get_connection_local_buffer_size(Http2_machine)

-spec get_connection_local_buffer_size(http2_machine()) -> non_neg_integer().

get_last_streamid(Http2_machine)

-spec get_last_streamid(http2_machine()) -> hackney_cow_http2:streamid().

get_local_setting(Key, Http2_machine)

-spec get_local_setting(atom(), http2_machine()) -> atom() | integer().

get_remote_settings(Http2_machine)

-spec get_remote_settings(http2_machine()) -> map().

get_stream_local_buffer_size(StreamID, State)

-spec get_stream_local_buffer_size(hackney_cow_http2:streamid(), http2_machine()) ->
                                      {ok, non_neg_integer()} | {error, not_found | closed}.

get_stream_local_state(StreamID, State)

-spec get_stream_local_state(hackney_cow_http2:streamid(), http2_machine()) ->
                                {ok, idle | hackney_cow_http2:fin(), empty | nofin | fin} |
                                {error, not_found | closed}.

get_stream_remote_state(StreamID, State)

-spec get_stream_remote_state(hackney_cow_http2:streamid(), http2_machine()) ->
                                 {ok, idle | hackney_cow_http2:fin()} | {error, not_found | closed}.

ignored_frame(State)

-spec ignored_frame(State) -> {ok, State} | {error, {connection_error, protocol_error, atom()}, State}
                       when State :: http2_machine().

init(_, Opts)

-spec init(client | server, opts()) -> {ok, iodata(), http2_machine()}.

init_stream(Method, State)

-spec init_stream(binary(), State) -> {ok, hackney_cow_http2:streamid(), State}
                     when State :: http2_machine().

init_upgrade_stream(Method, State)

-spec init_upgrade_stream(binary(), State) -> {ok, hackney_cow_http2:streamid(), State}
                             when State :: http2_machine().

is_lingering_stream(StreamID, Http2_machine)

-spec is_lingering_stream(hackney_cow_http2:streamid(), http2_machine()) -> boolean().

prepare_headers(StreamID, State, IsFin0, PseudoHeaders, Headers0)

-spec prepare_headers(hackney_cow_http2:streamid(),
                      State,
                      idle | hackney_cow_http2:fin(),
                      pseudo_headers(),
                      headers()) ->
                         {ok, hackney_cow_http2:fin(), iodata(), State}
                         when State :: http2_machine().

prepare_push_promise(StreamID, State, PseudoHeaders, Headers0)

-spec prepare_push_promise(hackney_cow_http2:streamid(), State, pseudo_headers(), headers()) ->
                              {ok, hackney_cow_http2:streamid(), iodata(), State} | {error, no_push}
                              when State :: http2_machine().

prepare_trailers(StreamID, State, Trailers)

-spec prepare_trailers(hackney_cow_http2:streamid(), State, headers()) -> {ok, iodata(), State}
                          when State :: http2_machine().

reset_stream(StreamID, State)

-spec reset_stream(hackney_cow_http2:streamid(), State) -> {ok, State} | {error, not_found}
                      when State :: http2_machine().

send_or_queue_data(StreamID, State, IsFin0, DataOrFileOrTrailers)

-spec send_or_queue_data(hackney_cow_http2:streamid(),
                         State,
                         hackney_cow_http2:fin(),
                         DataOrFileOrTrailers) ->
                            {ok, State} |
                            {send,
                             [{hackney_cow_http2:streamid(),
                               hackney_cow_http2:fin(),
                               [DataOrFileOrTrailers]}],
                             State}
                            when
                                State :: http2_machine(),
                                DataOrFileOrTrailers ::
                                    {data, iodata()} |
                                    #sendfile{offset :: non_neg_integer(),
                                              bytes :: pos_integer(),
                                              path :: file:name_all()} |
                                    {trailers, headers()}.

set_last_streamid(State)

-spec set_last_streamid(http2_machine()) -> {hackney_cow_http2:streamid(), http2_machine()}.

timeout(_, TRef, State)

-spec timeout(preface_timeout | settings_timeout, reference(), State) ->
                 {ok, State} | {error, {connection_error, hackney_cow_http2:error(), atom()}, State}
                 when State :: http2_machine().

update_window(Size, State)

-spec update_window(1..2147483647, State) -> State when State :: http2_machine().

update_window(StreamID, Size, State)

-spec update_window(hackney_cow_http2:streamid(), 1..2147483647, State) -> State
                       when State :: http2_machine().