Skip to content

Allow atom header keys in inform/3#1318

Merged
josevalim merged 3 commits into
elixir-plug:mainfrom
rodrigues:accept_atom
Jun 23, 2026
Merged

Allow atom header keys in inform/3#1318
josevalim merged 3 commits into
elixir-plug:mainfrom
rodrigues:accept_atom

Conversation

@rodrigues

@rodrigues rodrigues commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Hello plug team!

I've got an issue after upgrading plug, latest plug with latest bandit (1.12.0):

  ** (ArgumentError) errors were found at the given arguments:
    * 1st argument: not a binary
      (stdlib 7.3) :binary.match(:upgrade, [":", "\n", "\r", <<0>>])
      (plug 1.20.0) lib/plug/conn.ex:1994: Plug.Conn.validate_header_key_value!/2
      (plug 1.20.0) lib/plug/conn.ex:1440: anonymous fn/2 in Plug.Conn.adapter_inform/3
      (plug 1.20.0) lib/plug/conn.ex:1393: Plug.Conn.inform/3
      (bandit 1.12.0) lib/bandit/websocket/handshake.ex:28: Bandit.WebSocket.Handshake.do_handshake/3
      (bandit 1.12.0) lib/bandit/pipeline.ex:150: Bandit.Pipeline.maybe_upgrade!/1

Bandit websocket handshake calls Plug.Conn.inform(conn, 101, [{:upgrade, "websocket"}, ...]), passing the header key as an atom. Newest plug on validate_header_key_value!/2 calls :binary.match/2 on the key without coercion to binary, so atoms blow up.

Thank you!

@Fudoshiki

Copy link
Copy Markdown

Same error

[error] ** (ArgumentError) errors were found at the given arguments:

  * 1st argument: not a binary

    (stdlib 8.0.1) :binary.match(:upgrade, [":", "\n", "\r", <<0>>])
    (plug 1.20.0) lib/plug/conn.ex:1994: Plug.Conn.validate_header_key_value!/2
    (plug 1.20.0) lib/plug/conn.ex:1440: anonymous fn/2 in Plug.Conn.adapter_inform/3
    (elixir 1.20.2) lib/enum.ex:2622: Enum."-reduce/3-lists^foldl/2-0-"/3
    (plug 1.20.0) lib/plug/conn.ex:1439: Plug.Conn.adapter_inform/3
    (plug 1.20.0) lib/plug/conn.ex:1393: Plug.Conn.inform/3
    (bandit 1.12.0) lib/bandit/websocket/handshake.ex:28: Bandit.WebSocket.Handshake.do_handshake/3
    (bandit 1.12.0) lib/bandit/pipeline.ex:150: Bandit.Pipeline.maybe_upgrade!/1
    (bandit 1.12.0) lib/bandit/pipeline.ex:43: Bandit.Pipeline.run/5
    (bandit 1.12.0) lib/bandit/http1/handler.ex:13: Bandit.HTTP1.Handler.handle_data/3
    (bandit 1.12.0) lib/bandit/delegating_handler.ex:18: Bandit.DelegatingHandler.handle_data/3
    (bandit 1.12.0) lib/bandit/delegating_handler.ex:8: Bandit.DelegatingHandler.handle_continue/2
    (stdlib 8.0.1) gen_server.erl:2424: :gen_server.try_handle_continue/3
    (stdlib 8.0.1) gen_server.erl:2291: :gen_server.loop/4
    (stdlib 8.0.1) proc_lib.erl:333: :proc_lib.init_p_do_apply/3

@josevalim

Copy link
Copy Markdown
Member

Nowhere in Plug we assume headers can be atoms and I am not sure we should carve an exception here. :(

@josevalim

Copy link
Copy Markdown
Member

Ignore me, we document it as a keyword list.

Comment thread lib/plug/conn.ex Outdated
@josevalim josevalim merged commit 9df2c0a into elixir-plug:main Jun 23, 2026
2 checks passed
@josevalim

Copy link
Copy Markdown
Member

💚 💙 💜 💛 ❤️

@rodrigues rodrigues deleted the accept_atom branch June 23, 2026 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants