From 1932ed22159db57797d76faba8a21b17d5bdde90 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Thu, 17 Feb 2022 11:43:00 -0600 Subject: [PATCH] fix compatibility with mint_web_socket v0.2.0 (#46) --- CHANGELOG.md | 6 ++++++ lib/slipstream/connection/impl.ex | 16 ++++++++++++---- lib/slipstream/connection/pipeline.ex | 2 +- mix.exs | 2 +- mix.lock | 5 +++-- 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 63882f3..7ac70ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 0.8.4 - 2022-02-17 + +### Fixed + +- Fixed compatibility with `mint_web_socket` v0.2.0 + ## 0.8.3 - 2021-10-07 ### Fixed diff --git a/lib/slipstream/connection/impl.ex b/lib/slipstream/connection/impl.ex index 66c6c80..83dea60 100644 --- a/lib/slipstream/connection/impl.ex +++ b/lib/slipstream/connection/impl.ex @@ -17,18 +17,22 @@ defmodule Slipstream.Connection.Impl do def http_connect(config) do Mint.HTTP.connect( - map_scheme(config.uri.scheme), + map_http_scheme(config.uri.scheme), config.uri.host, config.uri.port, config.mint_opts ) end - defp map_scheme("wss"), do: :https - defp map_scheme(_), do: :http + defp map_http_scheme("wss"), do: :https + defp map_http_scheme(_), do: :http + + defp map_ws_scheme("wss"), do: :wss + defp map_ws_scheme(_), do: :ws def websocket_upgrade(conn, config) do Mint.WebSocket.upgrade( + map_ws_scheme(config.uri.scheme), conn, path(config.uri), config.headers, @@ -42,7 +46,11 @@ defmodule Slipstream.Connection.Impl do with {:ok, websocket, data} <- Mint.WebSocket.encode(state.websocket, frame), {:ok, conn} <- - Mint.HTTP.stream_request_body(state.conn, state.request_ref, data) do + Mint.WebSocket.stream_request_body( + state.conn, + state.request_ref, + data + ) do {:ok, %State{state | conn: conn, websocket: websocket}} else # coveralls-ignore-start diff --git a/lib/slipstream/connection/pipeline.ex b/lib/slipstream/connection/pipeline.ex index c94de2b..bd7cc61 100644 --- a/lib/slipstream/connection/pipeline.ex +++ b/lib/slipstream/connection/pipeline.ex @@ -137,7 +137,7 @@ defmodule Slipstream.Connection.Pipeline do end defp decode_message(p) do - case Mint.HTTP.stream(p.state.conn, p.raw_message) do + case Mint.WebSocket.stream(p.state.conn, p.raw_message) do {:ok, conn, messages} -> put_in(p.raw_message, messages) |> put_state(%State{p.state | conn: conn}) diff --git a/mix.exs b/mix.exs index 3be2ef6..b962329 100644 --- a/mix.exs +++ b/mix.exs @@ -64,7 +64,7 @@ defmodule Slipstream.MixProject do defp deps do [ - {:mint_web_socket, "~> 0.1"}, + {:mint_web_socket, "~> 0.2.0"}, {:telemetry, "~> 1.0 or ~> 0.4"}, {:jason, "~> 1.0", optional: true}, {:nimble_options, "~> 0.1"}, diff --git a/mix.lock b/mix.lock index 6de1ecc..879cb7d 100644 --- a/mix.lock +++ b/mix.lock @@ -13,6 +13,7 @@ "excoveralls": {:hex, :excoveralls, "0.14.2", "f9f5fd0004d7bbeaa28ea9606251bb643c313c3d60710bad1f5809c845b748f0", [:mix], [{:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "ca6fd358621cb4d29311b29d4732c4d47dac70e622850979bc54ed9a3e50f3e1"}, "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"}, "hackney": {:hex, :hackney, "1.18.0", "c4443d960bb9fba6d01161d01cd81173089686717d9490e5d3606644c48d121f", [:rebar3], [{:certifi, "~>2.8.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~>6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~>1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.3.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~>1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "9afcda620704d720db8c6a3123e9848d09c87586dc1c10479c42627b905b5c5e"}, + "hpax": {:hex, :hpax, "0.1.1", "2396c313683ada39e98c20a75a82911592b47e5c24391363343bde74f82396ca", [:mix], [], "hexpm", "0ae7d5a0b04a8a60caf7a39fcf3ec476f35cc2cc16c05abea730d3ce6ac6c826"}, "idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"}, "inch_ex": {:hex, :inch_ex, "2.1.0-rc.1", "7642a8902c0d2ed5d9b5754b2fc88fedf630500d630fc03db7caca2e92dedb36", [:mix], [{:bunt, "~> 0.2", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "4ceee988760f9382d1c1d0b93ea5875727f6071693e89a0a3c49c456ef1be75d"}, "jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"}, @@ -22,8 +23,8 @@ "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"}, "mime": {:hex, :mime, "2.0.1", "0de4c81303fe07806ebc2494d5321ce8fb4df106e34dd5f9d787b637ebadc256", [:mix], [], "hexpm", "7a86b920d2aedce5fb6280ac8261ac1a739ae6c1a1ad38f5eadf910063008942"}, "mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"}, - "mint": {:hex, :mint, "1.4.0", "cd7d2451b201fc8e4a8fd86257fb3878d9e3752899eb67b0c5b25b180bde1212", [:mix], [{:castore, "~> 0.1.0", [hex: :castore, repo: "hexpm", optional: true]}], "hexpm", "10a99e144b815cbf8522dccbc8199d15802440fc7a64d67b6853adb6fa170217"}, - "mint_web_socket": {:hex, :mint_web_socket, "0.1.4", "f83f7f0abbfacbb6f20017564c3469b3686c772615f7d5030a967ec946e0a6e3", [:mix], [{:mint, "~> 1.0", [hex: :mint, repo: "hexpm", optional: false]}], "hexpm", "b314953c2370087d4fb4d7d472978a166db83def89f9b21458b0ce48ceada7f0"}, + "mint": {:hex, :mint, "1.4.1", "49b3b6ea35a9a38836d2ad745251b01ca9ec062f7cb66f546bf22e6699137126", [:mix], [{:castore, "~> 0.1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:hpax, "~> 0.1.1", [hex: :hpax, repo: "hexpm", optional: false]}], "hexpm", "cd261766e61011a9079cccf8fa9d826e7a397c24fbedf0e11b49312bea629b58"}, + "mint_web_socket": {:hex, :mint_web_socket, "0.2.0", "375a426c863e0f99309aaf0bc23c901cbdd6a7346320c36e4ef29aa5dfd2e3b9", [:mix], [{:mint, "~> 1.4 and >= 1.4.1", [hex: :mint, repo: "hexpm", optional: false]}], "hexpm", "add635f7ae5f4a3e152ae3c104566175a4576a9802511319b764bab4c62b955c"}, "mox": {:hex, :mox, "1.0.0", "4b3c7005173f47ff30641ba044eb0fe67287743eec9bd9545e37f3002b0a9f8b", [:mix], [], "hexpm", "201b0a20b7abdaaab083e9cf97884950f8a30a1350a1da403b3145e213c6f4df"}, "nimble_options": {:hex, :nimble_options, "0.3.7", "1e52dd7673d36138b1a5dede183b5d86dff175dc46d104a8e98e396b85b04670", [:mix], [], "hexpm", "2086907e6665c6b6579be54ef5001928df5231f355f71ed258f80a55e9f63633"}, "nimble_parsec": {:hex, :nimble_parsec, "1.1.0", "3a6fca1550363552e54c216debb6a9e95bd8d32348938e13de5eda962c0d7f89", [:mix], [], "hexpm", "08eb32d66b706e913ff748f11694b17981c0b04a33ef470e33e11b3d3ac8f54b"},