Skip to content

Commit 2c47b8b

Browse files
feldSteffenDE
authored andcommitted
Support passing through the value of the sec-websocket-protocol header in the :connect-info
1 parent 52698bb commit 2c47b8b

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/phoenix/socket/transport.ex

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ defmodule Phoenix.Socket.Transport do
261261

262262
connect_info =
263263
Enum.map(connect_info, fn
264-
key when key in [:peer_data, :trace_context_headers, :uri, :user_agent, :x_headers] ->
264+
key when key in [:peer_data, :trace_context_headers, :uri, :user_agent, :x_headers, :sec_websocket_protocol] ->
265265
key
266266

267267
{:session, session} ->
@@ -272,7 +272,7 @@ defmodule Phoenix.Socket.Transport do
272272

273273
other ->
274274
raise ArgumentError,
275-
":connect_info keys are expected to be one of :peer_data, :trace_context_headers, :x_headers, :uri, or {:session, config}, " <>
275+
":connect_info keys are expected to be one of :peer_data, :trace_context_headers, :x_headers, :user_agent, :sec_websocket_protocol, :uri, or {:session, config}, " <>
276276
"optionally followed by custom keyword pairs, got: #{inspect(other)}"
277277
end)
278278

@@ -462,6 +462,8 @@ defmodule Phoenix.Socket.Transport do
462462
463463
* `:user_agent` - the value of the "user-agent" request header
464464
465+
* `:sec_websocket_protocol` - the value of the "sec-websocket-protocol" header
466+
465467
The CSRF check can be disabled by setting the `:check_csrf` option to `false`.
466468
"""
467469
def connect_info(conn, endpoint, keys, opts \\ []) do
@@ -482,6 +484,9 @@ defmodule Phoenix.Socket.Transport do
482484
:user_agent ->
483485
{:user_agent, fetch_user_agent(conn)}
484486

487+
:sec_websocket_protocol ->
488+
{:sec_websocket_protocol, Plug.Conn.get_req_header(conn, "sec-websocket-protocol")}
489+
485490
{:session, session} ->
486491
{:session, connect_session(conn, endpoint, session, opts)}
487492

0 commit comments

Comments
 (0)