Skip to content

Commit f664a53

Browse files
committed
Fix register_before_send with upgrade_adapter
Adds :set_upgrade state and runs before_send before calling upgrade.
1 parent 82cbff6 commit f664a53

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

lib/plug/conn.ex

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ defmodule Plug.Conn do
294294
alias Plug.Conn
295295
@epoch {{1970, 1, 1}, {0, 0, 0}}
296296
@already_sent {:plug_conn, :sent}
297-
@unsent [:unset, :set, :set_chunked, :set_file]
297+
@unsent [:unset, :set, :set_upgrade, :set_chunked, :set_file]
298298

299299
@doc """
300300
Assigns a value to a key in the connection.
@@ -1471,10 +1471,11 @@ defmodule Plug.Conn do
14711471
@spec upgrade_adapter(t, atom, term) :: t
14721472
def upgrade_adapter(%Conn{adapter: {adapter, payload}, state: state} = conn, protocol, args)
14731473
when state in @unsent do
1474+
conn = run_before_send(conn, :set_upgrade)
1475+
14741476
case adapter.upgrade(payload, protocol, args) do
14751477
{:ok, payload} ->
1476-
conn = run_before_send(conn, :upgraded)
1477-
%{conn | adapter: {adapter, payload}}
1478+
%{conn | state: :upgraded, adapter: {adapter, payload}}
14781479

14791480
{:error, :not_supported} ->
14801481
raise ArgumentError, "upgrade to #{protocol} not supported by #{inspect(adapter)}"

0 commit comments

Comments
 (0)