Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit already_sent event in adapter #475

Merged
merged 2 commits into from
Mar 20, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/bandit/adapter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ defmodule Bandit.Adapter do
# concerns, which are managed by the underlying `Bandit.HTTPTransport` implementation

@behaviour Plug.Conn.Adapter
@already_sent {:plug_conn, :sent}

defstruct transport: nil,
owner_pid: nil,
Expand Down Expand Up @@ -112,6 +113,7 @@ defmodule Bandit.Adapter do
|> send_headers(status, headers, :raw)
|> send_data(encoded_body, true)

send(adapter.owner_pid, @already_sent)
{:ok, nil, adapter}
end

Expand Down Expand Up @@ -144,6 +146,7 @@ defmodule Bandit.Adapter do
|> Map.put(:resp_start_time, start_time)
|> Map.put(:resp_end_time, Bandit.Telemetry.monotonic_time())

send(adapter.owner_pid, @already_sent)
{:ok, nil, %{adapter | transport: socket, metrics: metrics}}
else
raise "Cannot read #{length} bytes starting at #{offset} as #{path} is only #{size} octets in length"
Expand All @@ -158,6 +161,7 @@ defmodule Bandit.Adapter do

{headers, compression_context} = Bandit.Compression.new(adapter, status, headers, false, true)
adapter = %{adapter | metrics: metrics, compression_context: compression_context}
send(adapter.owner_pid, @already_sent)
{:ok, nil, send_headers(adapter, status, headers, :chunk_encoded)}
end

Expand Down