Skip to content

Commit

Permalink
Split header processing out into a message instead of a startup arg
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrudel committed Jan 18, 2024
1 parent 382b30d commit 988a389
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 28 deletions.
17 changes: 10 additions & 7 deletions lib/bandit/http2/stream.ex
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,17 @@ defmodule Bandit.HTTP2.Stream do
stream.stream_id,
initial_send_window_size,
transport_info,
headers,
plug,
connection_span,
opts
connection_span
) do
{:ok, pid} -> {:ok, %{stream | state: :open, pid: pid}}
:ignore -> {:error, "Unable to start stream process"}
other -> other
{:ok, pid} ->
StreamProcess.recv_headers(pid, headers, plug, opts)
{:ok, %{stream | state: :open, pid: pid}}

:ignore ->
{:error, "Unable to start stream process"}

other ->
other
end
end

Expand Down
37 changes: 16 additions & 21 deletions lib/bandit/http2/stream_process.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,31 @@ defmodule Bandit.HTTP2.StreamProcess do
Stream.stream_id(),
non_neg_integer(),
Bandit.TransportInfo.t(),
Plug.Conn.headers(),
Bandit.Pipeline.plug_def(),
Bandit.Telemetry.t(),
keyword()
) :: GenServer.on_start()
Bandit.Telemetry.t()
) ::
GenServer.on_start()
def start_link(
connection_pid,
stream_id,
initial_send_window_size,
transport_info,
headers,
plug,
connection_span,
opts
connection_span
) do
GenServer.start_link(__MODULE__, %{
connection_pid: connection_pid,
stream_id: stream_id,
initial_send_window_size: initial_send_window_size,
transport_info: transport_info,
headers: headers,
plug: plug,
connection_span: connection_span,
opts: opts
connection_span: connection_span
})
end

# Let the stream process know that header data has arrived from the client. This is implemented
# further down in this file as a handle_info callback
@spec recv_headers(pid(), Plug.Conn.headers(), Bandit.Pipeline.plug_def(), keyword()) ::
:ok | :noconnect | :nosuspend
def recv_headers(pid, headers, plug, opts), do: send(pid, {:headers, headers, plug, opts})

# Let the stream process know that body data has arrived from the client. The other half of this
# flow can be found in `Bandit.HTTP2.Adapter.read_req_body/2`
@spec recv_data(pid(), iodata()) :: :ok | :noconnect | :nosuspend
Expand Down Expand Up @@ -80,22 +78,19 @@ defmodule Bandit.HTTP2.StreamProcess do
|> Map.drop([:connection_span])
|> Map.put(:span, start_span(state.connection_span, state.stream_id))

{:ok, state, {:continue, :run}}
{:ok, state}
end

@dialyzer {:nowarn_function, handle_continue: 2}
@dialyzer {:nowarn_function, handle_info: 2}
@impl GenServer
def handle_continue(
:run,
def handle_info(
{:headers, all_headers, plug, opts},
%{
connection_pid: connection_pid,
stream_id: stream_id,
initial_send_window_size: initial_send_window_size,
transport_info: transport_info,
headers: all_headers,
plug: plug,
span: span,
opts: opts
span: span
} = state
) do
req =
Expand Down

0 comments on commit 988a389

Please sign in to comment.