Packages
ankh
0.8.9
0.17.0
0.16.0
0.15.0
0.14.5
0.14.4
0.14.3
0.14.2
0.14.1
0.14.0
0.13.0
0.12.1
0.12.0
0.11.0
0.10.0
0.9.0
0.8.11
0.8.10
0.8.9
0.8.8
0.8.7
0.8.6
0.8.5
0.8.4
0.8.3
0.8.2
0.8.1
0.8.0
0.7.2
0.7.1
0.7.0
0.6.0
0.5.3
0.5.2
0.5.1
0.5.0
0.4.6
0.4.5
0.4.4
0.4.3
0.4.2
0.4.1
0.4.0
0.3.1
0.3.0
0.1.1
0.1.0
0.0.5
0.0.4
0.0.3
0.0.2
0.0.1
Pure Elixir HTTP/2 implementation
Current section
Files
Jump to
Current section
Files
lib/ankh/http2/frame/registry.ex
defmodule Ankh.HTTP2.Frame.Registry do
@moduledoc """
Frame registry
"""
alias Ankh.HTTP2.Frame
alias Ankh.HTTP2.Frame.{
Continuation,
Data,
GoAway,
Headers,
Ping,
Priority,
PushPromise,
RstStream,
Settings,
WindowUpdate
}
alias Ankh.Protocol
@doc """
Returns frame struct for the given HTTP/2 frame type code
Codes 0-9 are reserved for standard frame types.
"""
@spec frame_for_type(Protocol.t() | nil, integer) :: {:ok, Frame.t()} | nil
def frame_for_type(_, 0x0), do: {:ok, Data}
def frame_for_type(_, 0x1), do: {:ok, Headers}
def frame_for_type(_, 0x2), do: {:ok, Priority}
def frame_for_type(_, 0x3), do: {:ok, RstStream}
def frame_for_type(_, 0x4), do: {:ok, Settings}
def frame_for_type(_, 0x5), do: {:ok, PushPromise}
def frame_for_type(_, 0x6), do: {:ok, Ping}
def frame_for_type(_, 0x7), do: {:ok, GoAway}
def frame_for_type(_, 0x8), do: {:ok, WindowUpdate}
def frame_for_type(_, 0x9), do: {:ok, Continuation}
def frame_for_type(protocol, type) when is_integer(type) and type > 9 and type < 256 do
case Registry.meta(__MODULE__, {protocol, type}) do
{:ok, type} ->
{:ok, type}
:error ->
{:error, :not_found}
end
end
@doc """
Registers a custom Frame struct for the given HTTP/2 frame type code
Codes 0-9 are reserved for standard frame types.
"""
@spec register(Protocol.t(), integer, Frame.t()) :: :ok
def register(connection, type, frame)
when is_integer(type) and type > 9 and type < 256 do
Registry.put_meta(__MODULE__, {connection, type}, frame)
end
end