Skip to content

Commit

Permalink
WiP
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrudel committed Jan 6, 2024
1 parent fd540ba commit 8167e0b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/bandit/http2/stream_task.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ defmodule Bandit.HTTP2.StreamTask do
# Handler module are fairly tightly coupled, but together they express clear APIs towards both
# Plug applications and the rest of Bandit.

use Task
use GenServer, restart: :temporary

# A stream process can be created only once we have an adapter & set of headers. Pass them in
# at creation time to ensure this invariant
Expand All @@ -32,7 +32,7 @@ defmodule Bandit.HTTP2.StreamTask do
Bandit.Telemetry.t()
) :: {:ok, pid()}
def start_link(req, transport_info, headers, plug, span) do
Task.start_link(__MODULE__, :run, [req, transport_info, headers, plug, span])
GenServer.start_link(__MODULE__, {req, transport_info, headers, plug, span})
end

# Let the stream task know that body data has arrived from the client. The other half of this
Expand All @@ -50,7 +50,11 @@ defmodule Bandit.HTTP2.StreamTask do
@spec recv_rst_stream(pid(), Bandit.HTTP2.Errors.error_code()) :: true
def recv_rst_stream(pid, error_code), do: Process.exit(pid, {:recv_rst_stream, error_code})

def run(req, transport_info, all_headers, plug, span) do
def init(state) do
{:ok, state, {:continue, :run}}
end

def handle_continue(:run, {req, transport_info, all_headers, plug, span}) do
with {:ok, request_target} <- build_request_target(all_headers),
method <- Bandit.Headers.get_header(all_headers, ":method"),
req <- %{req | method: method} do
Expand All @@ -74,7 +78,7 @@ defmodule Bandit.HTTP2.StreamTask do
status: conn.status
})

:ok
{:stop, :normal, {req, transport_info, all_headers, plug, span}}
else
{:error, reason} ->
raise Bandit.HTTP2.Stream.StreamError,
Expand Down

0 comments on commit 8167e0b

Please sign in to comment.