Lowercase "upgrade" value in Connection header may prevent connection upgrade

オープン 初心者向け
#42 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
74/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
静か
技術スタック
elixir
領域
networking

調査の方向性

Mint.WebSocket.Utils.headers/2 から始め、特に issue に示されている HTTP/1 ヘッダーリストを確認し、Mint がヘッダーの大文字と小文字をどのように扱っているかを調べてください。報告されたサーバー、または同等の HTTP/1 エンドポイントに対して websocket upgrade を再現し、その後、重複したカスタム Connection ヘッダーを必要とせずに生成されたハンドシェイクが受け入れられることを確認してください。

索引モデルが issue の本文から書いたものです。

説明

  1. Description of issue

I wasted several hours today trying to figure out why MintWebSocket.upgrade/5 was failing when connecting to a websocket at wss://demo.rss.chat/

I noted that other websocket clients were succeeding and went to compare the headers that were sent at the upgrade request.

This particular server rejects the standard Mint.WebSocket.upgrade/5 call with a status 400 and a somewhat misleading message:

HTTP/1.1 400 Bad Request
Alt-Svc: h3=":443"; ma=2592000
Content-Type: text/html
Date: Mon, 17 Aug 2026 00:13:04 GMT
Server: Caddy
Transfer-Encoding: chunked

34
This HTTP server can't handle WebSocket connections.

I finally tracked down the issue to the fact that MintWebSocket.upgrade/5 sends a Connection header with the value "upgrade" in lowercase. When that is changed to "Upgrade" (capitalized), the socket is upgraded successfully.

  1. Possible fix

Mint.WebSocket.Utils.headers/2 shows the following:

  # header names are written in their conventional casing: Mint lowercases them
  # unless the connection was opened with `case_sensitive_headers: true`
  def headers({:http1, nonce}, extensions) when is_binary(nonce) do
    [
      {"Upgrade", "websocket"},
      {"Connection", "upgrade"},
      {"Sec-WebSocket-Version", "13"},
      {"Sec-WebSocket-Key", nonce},
      {"Sec-WebSocket-Extensions", extension_string(extensions)}
    ]
    |> Enum.reject(fn {_k, v} -> v == "" end)
  end

When I changed {"Connection", "upgrade"} to {"Connection", "Upgrade"} (capitalized), the connection succeeded. All of the non-normative examples in RFC6445 section 1.1 and 1.2 show the handshake headers using the capitalized "Upgrade" and the lowercase "websocket".

I believe that Mint.WebSocket.Utils.headers/2 should return the capitalized version.

For this particular server I was able to connect by supplying my own {"Connection", "Upgrade"} header (so that both values, "upgrade" and "Upgrade", are sent to the server in that order), but I don't know if that will work generally or not.

主要言語
Elixir
スター
151
フォーク
17
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

elixir-mint/mint_web_socket のほかの issue

elixir-mint/mint_web_socket の issue をすべて見る

似ている issue

Elixir の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。