From d501488f4d8084441e293e29c2e3835bd2508dc0 Mon Sep 17 00:00:00 2001 From: Richard Kallos Date: Tue, 29 Nov 2022 15:05:07 -0500 Subject: [PATCH 01/15] Add Dialyxir dependency --- mix.exs | 3 ++- mix.lock | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/mix.exs b/mix.exs index 005b99c7..7aedaef1 100644 --- a/mix.exs +++ b/mix.exs @@ -41,7 +41,8 @@ defmodule MintWebSocket.MixProject do {:jason, ">= 0.0.0", only: [:dev, :test]}, {:cowboy, "~> 2.9", only: [:test]}, {:gun, "== 2.0.0-rc.2", only: [:test]}, - {:excoveralls, "~> 0.14", only: [:test]} + {:excoveralls, "~> 0.14", only: [:test]}, + {:dialyxir, "~> 1.2", only: [:dev, :test], runtime: false} ] end diff --git a/mix.lock b/mix.lock index 61d895b6..3e8dca27 100644 --- a/mix.lock +++ b/mix.lock @@ -3,7 +3,9 @@ "certifi": {:hex, :certifi, "2.9.0", "6f2a475689dd47f19fb74334859d460a2dc4e3252a3324bd2111b8f0429e7e21", [:rebar3], [], "hexpm", "266da46bdb06d6c6d35fde799bcb28d36d985d424ad7c08b5bb48f5b5cdd4641"}, "cowboy": {:hex, :cowboy, "2.9.0", "865dd8b6607e14cf03282e10e934023a1bd8be6f6bacf921a7e2a96d800cd452", [:make, :rebar3], [{:cowlib, "2.11.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "2c729f934b4e1aa149aff882f57c6372c15399a20d54f65c8d67bef583021bde"}, "cowlib": {:hex, :cowlib, "2.11.0", "0b9ff9c346629256c42ebe1eeb769a83c6cb771a6ee5960bd110ab0b9b872063", [:make, :rebar3], [], "hexpm", "2b3e9da0b21c4565751a6d4901c20d1b4cc25cbb7fd50d91d2ab6dd287bc86a9"}, + "dialyxir": {:hex, :dialyxir, "1.2.0", "58344b3e87c2e7095304c81a9ae65cb68b613e28340690dfe1a5597fd08dec37", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "61072136427a851674cab81762be4dbeae7679f85b1272b6d25c3a839aff8463"}, "earmark_parser": {:hex, :earmark_parser, "1.4.25", "2024618731c55ebfcc5439d756852ec4e85978a39d0d58593763924d9a15916f", [:mix], [], "hexpm", "56749c5e1c59447f7b7a23ddb235e4b3defe276afc220a6227237f3efe83f51e"}, + "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, "ex_doc": {:hex, :ex_doc, "0.28.4", "001a0ea6beac2f810f1abc3dbf4b123e9593eaa5f00dd13ded024eae7c523298", [:mix], [{:earmark_parser, "~> 1.4.19", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "bf85d003dd34911d89c8ddb8bda1a958af3471a274a4c2150a9c01c78ac3f8ed"}, "excoveralls": {:hex, :excoveralls, "0.14.4", "295498f1ae47bdc6dce59af9a585c381e1aefc63298d48172efaaa90c3d251db", [:mix], [{:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "e3ab02f2df4c1c7a519728a6f0a747e71d7d6e846020aae338173619217931c1"}, "gun": {:hex, :gun, "2.0.0-rc.2", "7c489a32dedccb77b6e82d1f3c5a7dadfbfa004ec14e322cdb5e579c438632d2", [:make, :rebar3], [{:cowlib, "2.11.0", [hex: :cowlib, repo: "hexpm", optional: false]}], "hexpm", "6b9d1eae146410d727140dbf8b404b9631302ecc2066d1d12f22097ad7d254fc"}, From 5e5090b4d21f46a89a8b089fca68a95cdecfe941 Mon Sep 17 00:00:00 2001 From: Richard Kallos Date: Tue, 29 Nov 2022 15:13:39 -0500 Subject: [PATCH 02/15] Add @type spec for UpgradeFailureError --- lib/mint/web_socket/upgrade_failure_error.ex | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/mint/web_socket/upgrade_failure_error.ex b/lib/mint/web_socket/upgrade_failure_error.ex index 6ea2b8c5..4008786b 100644 --- a/lib/mint/web_socket/upgrade_failure_error.ex +++ b/lib/mint/web_socket/upgrade_failure_error.ex @@ -3,6 +3,10 @@ defmodule Mint.WebSocket.UpgradeFailureError do An error representing a failure to upgrade protocols from HTTP to WebSocket """ + @type t() :: %__MODULE__{ + status_code: pos_integer, + headers: [Mint.Types.headers()] + } defexception [:status_code, :headers] def message(%__MODULE__{} = error) do From 2e0f947051cba90db15a7e440bde155c7efa0efa Mon Sep 17 00:00:00 2001 From: Richard Kallos Date: Tue, 29 Nov 2022 16:43:58 -0500 Subject: [PATCH 03/15] Fix Extension.decode/2 spec --- lib/mint/web_socket/extension.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mint/web_socket/extension.ex b/lib/mint/web_socket/extension.ex index 8b29b57b..043043c2 100644 --- a/lib/mint/web_socket/extension.ex +++ b/lib/mint/web_socket/extension.ex @@ -180,7 +180,7 @@ defmodule Mint.WebSocket.Extension do end @doc false - @spec decode(tuple(), [t()]) :: {:ok, tuple(), [t()]} | {:error, term()} + @spec decode(tuple(), [t()]) :: {tuple(), [t()]} | {{:error, term()}, [t()]} def decode(frame, extensions) do decode_all_extensions(frame, extensions, []) end From ea131e3ca17cdcd21e6d5dfd51f3b68aa55725ff Mon Sep 17 00:00:00 2001 From: Richard Kallos Date: Tue, 29 Nov 2022 16:51:50 -0500 Subject: [PATCH 04/15] Fix Extension.encode/2 spec --- lib/mint/web_socket/extension.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mint/web_socket/extension.ex b/lib/mint/web_socket/extension.ex index 043043c2..2fdf6b0e 100644 --- a/lib/mint/web_socket/extension.ex +++ b/lib/mint/web_socket/extension.ex @@ -156,7 +156,7 @@ defmodule Mint.WebSocket.Extension do defstruct [:name, :module, :state, opts: [], params: []] @doc false - @spec encode(tuple(), [t()]) :: {:ok, tuple(), [t()]} | {:error, term()} + @spec encode(tuple(), [t()]) :: {tuple(), [t()]} | no_return() def encode(frame, extensions) do encode_all_extensions(frame, extensions, []) end From 9749c1f2df0fd64563c83a7d99bb80d5219b2f7f Mon Sep 17 00:00:00 2001 From: Richard Kallos Date: Tue, 29 Nov 2022 16:57:59 -0500 Subject: [PATCH 05/15] Fix encode_to_binary/1 spec --- lib/mint/web_socket/frame.ex | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/lib/mint/web_socket/frame.ex b/lib/mint/web_socket/frame.ex index c7ab42f2..4167c1cb 100644 --- a/lib/mint/web_socket/frame.ex +++ b/lib/mint/web_socket/frame.ex @@ -21,6 +21,34 @@ defmodule Mint.WebSocket.Frame do defrecord :ping, shared defrecord :pong, shared + @type continuation_frame() :: + record(:continuation, reserved: binary(), mask: binary, data: binary, fin?: boolean) + @type text_frame() :: + record(:text, reserved: binary(), mask: binary, data: binary, fin?: boolean) + @type binary_frame() :: + record(:binary, reserved: binary(), mask: binary, data: binary, fin?: boolean) + @type close_frame() :: + record(:close, + reserved: binary(), + mask: binary, + data: binary, + fin?: boolean, + code: binary(), + reason: binary() + ) + @type ping_frame() :: + record(:ping, reserved: binary(), mask: binary, data: binary, fin?: boolean) + @type pong_frame() :: + record(:pong, reserved: binary(), mask: binary, data: binary, fin?: boolean) + + @type frame_record() :: + continuation_frame() + | text_frame() + | binary_frame() + | close_frame() + | ping_frame() + | pong_frame() + defguard is_control(frame) when is_tuple(frame) and (elem(frame, 0) == :close or elem(frame, 0) == :ping or elem(frame, 0) == :pong) @@ -60,6 +88,9 @@ defmodule Mint.WebSocket.Frame do def new_mask, do: :crypto.strong_rand_bytes(4) + @spec encode(Mint.WebSocket.t(), Mint.WebSocket.frame()) :: + {:ok, Mint.WebSocket.t(), bitstring()} + | {:error, Mint.WebSocket.t(), WebSocketError.t()} def encode(websocket, frame) when is_friendly_frame(frame) do {frame, extensions} = frame @@ -74,7 +105,7 @@ defmodule Mint.WebSocket.Frame do :throw, {:mint, reason} -> {:error, websocket, reason} end - @spec encode_to_binary(tuple()) :: binary() + @spec encode_to_binary(frame_record()) :: bitstring() defp encode_to_binary(frame) do payload = payload(frame) mask = mask(frame) @@ -340,7 +371,6 @@ defmodule Mint.WebSocket.Frame do # translate from user-friendly tuple into record defined in this module # (and the reverse) @spec translate(Mint.WebSocket.frame() | Mint.WebSocket.shorthand_frame()) :: tuple() - @spec translate(tuple) :: Mint.WebSocket.frame() for opcode <- Map.keys(@opcodes) do def translate(unquote(opcode)(reserved: <>)) when reserved != <<0::size(3)>> do From b0ed86b96dacb4a66a19ebb334c5cb55bcbc9f65 Mon Sep 17 00:00:00 2001 From: Richard Kallos Date: Tue, 29 Nov 2022 17:20:30 -0500 Subject: [PATCH 06/15] Use Mint.HTTP.* when possible --- lib/mint/web_socket.ex | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/mint/web_socket.ex b/lib/mint/web_socket.ex index 79128ff2..04122767 100644 --- a/lib/mint/web_socket.ex +++ b/lib/mint/web_socket.ex @@ -267,7 +267,7 @@ defmodule Mint.WebSocket do headers = Utils.headers({:http1, nonce}, extensions) ++ headers - Mint.HTTP1.request(conn, "GET", path, headers, nil) + Mint.HTTP.request(conn, "GET", path, headers, nil) end defp do_upgrade(scheme, :http2, conn, path, headers, opts) do @@ -395,7 +395,7 @@ defmodule Mint.WebSocket do # we take manual control of the :gen_tcp and :ssl messages in HTTP/1 because # we have taken over the transport defp stream_http1(conn, request_ref, message) do - socket = HTTP1.get_socket(conn) + socket = Mint.HTTP.get_socket(conn) tag = if get_private(conn, :scheme) == :ws, do: :tcp, else: :ssl case message do @@ -403,7 +403,7 @@ defmodule Mint.WebSocket do reset_mode(conn, [{:data, request_ref, data}]) _ -> - HTTP1.stream(conn, message) + Mint.HTTP.stream(conn, message) end end @@ -411,7 +411,7 @@ defmodule Mint.WebSocket do module = if get_private(conn, :scheme) == :ws, do: :inet, else: :ssl with :active <- get_private(conn, :mode), - {:error, reason} <- module.setopts(HTTP1.get_socket(conn), active: :once) do + {:error, reason} <- module.setopts(Mint.HTTP.get_socket(conn), active: :once) do {:error, conn, %Mint.TransportError{reason: reason}, responses} else _ -> {:ok, conn, responses} @@ -448,7 +448,7 @@ defmodule Mint.WebSocket do defp recv_http1(conn, request_ref, byte_count, timeout) do module = if get_private(conn, :scheme) == :ws, do: :gen_tcp, else: :ssl - socket = HTTP1.get_socket(conn) + socket = Mint.HTTP.get_socket(conn) case module.recv(socket, byte_count, timeout) do {:ok, data} -> @@ -498,7 +498,7 @@ defmodule Mint.WebSocket do defp stream_request_body_http1(conn, data) do transport = if get_private(conn, :scheme) == :ws, do: :gen_tcp, else: :ssl - case transport.send(Mint.HTTP1.get_socket(conn), data) do + case transport.send(Mint.HTTP.get_socket(conn), data) do :ok -> {:ok, conn} {:error, reason} -> {:error, conn, %Mint.TransportError{reason: reason}} end From ca41e22993c9b28a354fb2eadd75bfc008bfc902 Mon Sep 17 00:00:00 2001 From: Richard Kallos Date: Tue, 29 Nov 2022 17:21:05 -0500 Subject: [PATCH 07/15] Disable no_opaque on do_upgrade for http2 --- lib/mint/web_socket.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/mint/web_socket.ex b/lib/mint/web_socket.ex index 04122767..4b4fce78 100644 --- a/lib/mint/web_socket.ex +++ b/lib/mint/web_socket.ex @@ -112,7 +112,6 @@ defmodule Mint.WebSocket do alias __MODULE__.{Utils, Extension, Frame} alias Mint.{WebSocketError, WebSocket.UpgradeFailureError} - alias Mint.{HTTP1, HTTP2} import Mint.HTTP, only: [get_private: 2, put_private: 3, protocol: 1] @typedoc """ @@ -270,8 +269,9 @@ defmodule Mint.WebSocket do Mint.HTTP.request(conn, "GET", path, headers, nil) end + @dialyzer {:no_opaque, do_upgrade: 6} defp do_upgrade(scheme, :http2, conn, path, headers, opts) do - if HTTP2.get_server_setting(conn, :enable_connect_protocol) == true do + if Mint.HTTP2.get_server_setting(conn, :enable_connect_protocol) == true do extensions = get_extensions(opts) conn = put_private(conn, :extensions, extensions) From e3f7ae44a30cc3068f59617a47cd10821cd441de Mon Sep 17 00:00:00 2001 From: Richard Kallos Date: Tue, 29 Nov 2022 17:59:10 -0500 Subject: [PATCH 08/15] Remove unused 'use' and init/1 --- test/fixtures/test_server.ex | 8 +------- test/mint/web_socket_test.exs | 3 +-- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/test/fixtures/test_server.ex b/test/fixtures/test_server.ex index b6be9d89..1d91a6fc 100644 --- a/test/fixtures/test_server.ex +++ b/test/fixtures/test_server.ex @@ -3,9 +3,7 @@ defmodule TestServer do A supervisor for the WebsocketHandler """ - use Supervisor - - def start_link(_opts) do + def start() do dispatch = :cowboy_router.compile([ {:_, @@ -21,9 +19,5 @@ defmodule TestServer do env: %{dispatch: dispatch}, enable_connect_protocol: true }) - - Supervisor.start_link([], strategy: :one_for_one) end - - def init(_opts), do: {:ok, nil} end diff --git a/test/mint/web_socket_test.exs b/test/mint/web_socket_test.exs index 41bedbbd..7c20e9e1 100644 --- a/test/mint/web_socket_test.exs +++ b/test/mint/web_socket_test.exs @@ -4,8 +4,7 @@ defmodule Mint.WebSocketTest do alias Mint.{HTTP1, HTTP2, WebSocket, WebSocket.UpgradeFailureError} setup_all do - # a cowboy test server used by the HTTP/2 tests - start_supervised!(TestServer) + TestServer.start() :ok end From 1ca0b9fa322bdcb1f40e845c32dc4d06c177d5c2 Mon Sep 17 00:00:00 2001 From: Richard Kallos Date: Tue, 29 Nov 2022 18:53:27 -0500 Subject: [PATCH 09/15] Remove (seemingly?) unused guard clause --- test/fixtures/autobahn_client.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fixtures/autobahn_client.ex b/test/fixtures/autobahn_client.ex index 08837a4a..11157a26 100644 --- a/test/fixtures/autobahn_client.ex +++ b/test/fixtures/autobahn_client.ex @@ -10,7 +10,7 @@ defmodule AutobahnClient do defstruct [:conn, :websocket, :ref, messages: [], next: :cont, sent_close?: false, buffer: <<>>] defguardp is_close_frame(frame) - when frame == :close or (is_tuple(frame) and elem(frame, 0) == :close) + when is_tuple(frame) and elem(frame, 0) == :close def get_case_count do %{messages: [{:text, count} | _]} = connect("/getCaseCount") |> decode_buffer() From 84d06b05c01a818cc341e9c2fbd8e1835c9e4727 Mon Sep 17 00:00:00 2001 From: Richard Kallos Date: Tue, 29 Nov 2022 18:53:57 -0500 Subject: [PATCH 10/15] Replace with expression with separate functions This helps to avoid matching on opaque structures, and removes the ambiguity that Dialyzer appeared to struggle with --- test/fixtures/autobahn_client.ex | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/test/fixtures/autobahn_client.ex b/test/fixtures/autobahn_client.ex index 11157a26..8f24eb86 100644 --- a/test/fixtures/autobahn_client.ex +++ b/test/fixtures/autobahn_client.ex @@ -149,18 +149,24 @@ defmodule AutobahnClient do def send(state, frame) do Logger.debug("Sending #{inspect(frame, printable_limit: 30)}") - with {:ok, %Mint.WebSocket{} = websocket, data} <- - Mint.WebSocket.encode(state.websocket, frame), - {:ok, conn} <- Mint.WebSocket.stream_request_body(state.conn, state.ref, data) do - Logger.debug("Sent.") - %__MODULE__{state | conn: conn, websocket: websocket, sent_close?: is_close_frame(frame)} - else - {:error, %Mint.WebSocket{} = websocket, reason} -> + case Mint.WebSocket.encode(state.websocket, frame) do + {:ok, websocket, data} -> + do_send(put_in(state.websocket, websocket), frame, data) + + {:error, websocket, reason} -> Logger.debug( "Could not send frame #{inspect(frame, printable_limit: 30)} because #{inspect(reason)}, sending close..." ) send(put_in(state.websocket, websocket), {:close, 1002, ""}) + end + end + + defp do_send(state, frame, data) do + case Mint.WebSocket.stream_request_body(state.conn, state.ref, data) do + {:ok, conn} -> + Logger.debug("Sent.") + %__MODULE__{state | conn: conn, sent_close?: is_close_frame(frame)} {:error, conn, %Mint.TransportError{reason: :closed}} -> Logger.debug( From fe505fafed9fd70ab680a2670fcebcbb857a007b Mon Sep 17 00:00:00 2001 From: Richard Kallos Date: Tue, 29 Nov 2022 19:08:22 -0500 Subject: [PATCH 11/15] Set PLT path --- .gitignore | 4 ++++ mix.exs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/.gitignore b/.gitignore index 8948a89f..c66f632c 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,7 @@ mint_web_socket-*.tar # Temporary files for e.g. tests /tmp + +# Dialyzer PLTs +/priv/plts/*.plt +/priv/plts/*.plt.hash diff --git a/mix.exs b/mix.exs index 7aedaef1..c07efc79 100644 --- a/mix.exs +++ b/mix.exs @@ -19,6 +19,10 @@ defmodule MintWebSocket.MixProject do "coveralls.github": :test, docs: :dev ], + dialyzer: [ + plt_local_path: "priv/plts", + plt_add_apps: [:mix] + ], package: package(), description: description(), source_url: @source_url, From 6d394f37eac7c2ce759e5f26480af700f023a93f Mon Sep 17 00:00:00 2001 From: Richard Kallos Date: Tue, 29 Nov 2022 19:09:30 -0500 Subject: [PATCH 12/15] Add dialyzer to CI (with caching of PLTs) --- .github/workflows/main.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index edb54728..289b431f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,6 +18,7 @@ jobs: lint: true coverage: true report: true + dialyzer: true - erlang: "24.3" elixir: "1.12" - erlang: "23.3.1" @@ -65,6 +66,26 @@ jobs: run: mix compile --warnings-as-errors if: ${{ matrix.lint }} + - name: Restore cached PLTs + uses: actions/cache@v3 + id: plt_cache + with: + key: | + ${{ runner.os }}-${{ matrix.elixir }}-${{ matrix.erlang }}-plt + restore-keys: | + ${{ runner.os }}-${{ matrix.elixir }}-${{ matrix.erlang }}-plt + path: | + priv/plts + + # Create PLTs if no cached PLTs were found + - name: Create PLTs + if: steps.plt_cache.outputs.cache-hit != 'true' + run: MIX_ENV=test mix dialyzer --plt + + - name: Run dialyzer + run: MIX_ENV=test mix dialyzer + if: ${{ matrix.dialyzer }} + - name: Run tests with coverage run: mix coveralls.github if: ${{ matrix.coverage }} From 415a8ab76ff72f7c0b585e6c83435524726213e1 Mon Sep 17 00:00:00 2001 From: Richard Kallos Date: Sat, 3 Dec 2022 11:34:30 -0500 Subject: [PATCH 13/15] Use Mint.Types.status() for status_code --- lib/mint/web_socket/upgrade_failure_error.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mint/web_socket/upgrade_failure_error.ex b/lib/mint/web_socket/upgrade_failure_error.ex index 4008786b..e142cba0 100644 --- a/lib/mint/web_socket/upgrade_failure_error.ex +++ b/lib/mint/web_socket/upgrade_failure_error.ex @@ -4,7 +4,7 @@ defmodule Mint.WebSocket.UpgradeFailureError do """ @type t() :: %__MODULE__{ - status_code: pos_integer, + status_code: Mint.Types.status(), headers: [Mint.Types.headers()] } defexception [:status_code, :headers] From c90c1766357793c45f21ffcac2b7f68efaf5252b Mon Sep 17 00:00:00 2001 From: Richard Kallos Date: Sat, 3 Dec 2022 11:34:43 -0500 Subject: [PATCH 14/15] Specify .reserved as length 3 bitstring --- lib/mint/web_socket/frame.ex | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/mint/web_socket/frame.ex b/lib/mint/web_socket/frame.ex index 4167c1cb..35c88f20 100644 --- a/lib/mint/web_socket/frame.ex +++ b/lib/mint/web_socket/frame.ex @@ -22,14 +22,14 @@ defmodule Mint.WebSocket.Frame do defrecord :pong, shared @type continuation_frame() :: - record(:continuation, reserved: binary(), mask: binary, data: binary, fin?: boolean) + record(:continuation, reserved: <<_::3>>, mask: binary, data: binary, fin?: boolean) @type text_frame() :: - record(:text, reserved: binary(), mask: binary, data: binary, fin?: boolean) + record(:text, reserved: <<_::3>>, mask: binary, data: binary, fin?: boolean) @type binary_frame() :: - record(:binary, reserved: binary(), mask: binary, data: binary, fin?: boolean) + record(:binary, reserved: <<_::3>>, mask: binary, data: binary, fin?: boolean) @type close_frame() :: record(:close, - reserved: binary(), + reserved: <<_::3>>, mask: binary, data: binary, fin?: boolean, @@ -37,9 +37,9 @@ defmodule Mint.WebSocket.Frame do reason: binary() ) @type ping_frame() :: - record(:ping, reserved: binary(), mask: binary, data: binary, fin?: boolean) + record(:ping, reserved: <<_::3>>, mask: binary, data: binary, fin?: boolean) @type pong_frame() :: - record(:pong, reserved: binary(), mask: binary, data: binary, fin?: boolean) + record(:pong, reserved: <<_::3>>, mask: binary, data: binary, fin?: boolean) @type frame_record() :: continuation_frame() From 420d2103b6de22176c20312dfdec48adc91b893f Mon Sep 17 00:00:00 2001 From: Richard Kallos Date: Mon, 5 Dec 2022 14:59:10 -0500 Subject: [PATCH 15/15] Make continuation_frame() private. Add () to type names --- lib/mint/web_socket/frame.ex | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/mint/web_socket/frame.ex b/lib/mint/web_socket/frame.ex index 35c88f20..fc96150e 100644 --- a/lib/mint/web_socket/frame.ex +++ b/lib/mint/web_socket/frame.ex @@ -21,25 +21,30 @@ defmodule Mint.WebSocket.Frame do defrecord :ping, shared defrecord :pong, shared - @type continuation_frame() :: - record(:continuation, reserved: <<_::3>>, mask: binary, data: binary, fin?: boolean) + @typep continuation_frame() :: + record(:continuation, + reserved: <<_::3>>, + mask: binary(), + data: binary(), + fin?: boolean() + ) @type text_frame() :: - record(:text, reserved: <<_::3>>, mask: binary, data: binary, fin?: boolean) + record(:text, reserved: <<_::3>>, mask: binary(), data: binary(), fin?: boolean()) @type binary_frame() :: - record(:binary, reserved: <<_::3>>, mask: binary, data: binary, fin?: boolean) + record(:binary, reserved: <<_::3>>, mask: binary(), data: binary(), fin?: boolean()) @type close_frame() :: record(:close, reserved: <<_::3>>, - mask: binary, - data: binary, - fin?: boolean, + mask: binary(), + data: binary(), + fin?: boolean(), code: binary(), reason: binary() ) @type ping_frame() :: - record(:ping, reserved: <<_::3>>, mask: binary, data: binary, fin?: boolean) + record(:ping, reserved: <<_::3>>, mask: binary(), data: binary(), fin?: boolean()) @type pong_frame() :: - record(:pong, reserved: <<_::3>>, mask: binary, data: binary, fin?: boolean) + record(:pong, reserved: <<_::3>>, mask: binary(), data: binary(), fin?: boolean()) @type frame_record() :: continuation_frame()