From 8167e0bc9b358e3e384da749c548b970bab6128f Mon Sep 17 00:00:00 2001 From: Mat Trudel Date: Sat, 6 Jan 2024 15:52:59 -0500 Subject: [PATCH] WiP --- lib/bandit/http2/stream_task.ex | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/bandit/http2/stream_task.ex b/lib/bandit/http2/stream_task.ex index cead2d4f..12bea63d 100644 --- a/lib/bandit/http2/stream_task.ex +++ b/lib/bandit/http2/stream_task.ex @@ -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 @@ -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 @@ -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 @@ -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,