Skip to content

Commit 975a5ac

Browse files
committed
Emit {:plug_conn, :sent} on responses
1 parent e5d5fd8 commit 975a5ac

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/plug/cowboy/conn.ex

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ defmodule Plug.Cowboy.Conn do
22
@behaviour Plug.Conn.Adapter
33
@moduledoc false
44

5+
@already_sent {:plug_conn, :sent}
6+
57
def conn(req) do
68
%{
79
path: path,
@@ -14,7 +16,7 @@ defmodule Plug.Cowboy.Conn do
1416
} = req
1517

1618
%Plug.Conn{
17-
adapter: {__MODULE__, req},
19+
adapter: {__MODULE__, Map.put(req, :plug_pid, self())},
1820
host: host,
1921
method: method,
2022
owner: self(),
@@ -33,6 +35,7 @@ defmodule Plug.Cowboy.Conn do
3335
req = to_headers_map(req, headers)
3436
status = Integer.to_string(status) <> " " <> Plug.Conn.Status.reason_phrase(status)
3537
req = :cowboy_req.reply(status, %{}, body, req)
38+
send(req.plug_pid, @already_sent)
3639
{:ok, nil, req}
3740
end
3841

@@ -49,13 +52,15 @@ defmodule Plug.Cowboy.Conn do
4952
body = {:sendfile, offset, length, path}
5053
req = to_headers_map(req, headers)
5154
req = :cowboy_req.reply(status, %{}, body, req)
55+
send(req.plug_pid, @already_sent)
5256
{:ok, nil, req}
5357
end
5458

5559
@impl true
5660
def send_chunked(req, status, headers) do
5761
req = to_headers_map(req, headers)
5862
req = :cowboy_req.stream_reply(status, %{}, req)
63+
send(req.plug_pid, @already_sent)
5964
{:ok, nil, req}
6065
end
6166

0 commit comments

Comments
 (0)