From 530ba279d919b17a903f10ac9aeb39baf8c019e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Meadows-J=C3=B6nsson?= Date: Tue, 13 Feb 2024 17:03:09 +0100 Subject: [PATCH] Deprecate :read_write option on HTTP.open?/2 (#426) --- lib/mint/core/conn.ex | 2 +- lib/mint/http.ex | 10 +++++----- lib/mint/http1.ex | 5 +++-- lib/mint/http2.ex | 4 ++-- lib/mint/unsafe_proxy.ex | 4 ++-- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/mint/core/conn.ex b/lib/mint/core/conn.ex index 4e062791..12af3b2c 100644 --- a/lib/mint/core/conn.ex +++ b/lib/mint/core/conn.ex @@ -13,7 +13,7 @@ defmodule Mint.Core.Conn do keyword() ) :: {:ok, conn()} | {:error, Types.error()} - @callback open?(conn(), :read | :write | :read_write) :: boolean() + @callback open?(conn(), :read | :write) :: boolean() @callback close(conn()) :: {:ok, conn()} diff --git a/lib/mint/http.ex b/lib/mint/http.ex index dffad505..f3023af6 100644 --- a/lib/mint/http.ex +++ b/lib/mint/http.ex @@ -509,16 +509,16 @@ defmodule Mint.HTTP do either open, or closed (for both reading and writing). In HTTP/2, the connection can be closed only for writing but not for reading, meaning that you cannot send any more data to the server but you can still receive data from the server. In this case, `Mint.HTTP.open?(conn, :read)` - would return `true` but `Mint.HTTP.open?(conn, :read_write)` would return `false`. + would return `true` but `Mint.HTTP.open?(conn, :write)` would return `false`. See the "Closed connection" section in the module documentation of `Mint.HTTP2`. If a connection is *completely closed* (that is, `Mint.HTTP.open?(conn, :read)` returns `false`), it has become useless and you should get rid of it. If you still need a connection to the server, start a new connection with `connect/4`. - > #### The default value of `type` is `:read_write` {: .warning} + > #### The default value of `type` is `:write` {: .warning} > - > With the default value of `type` being `:read_write`, a call to + > With the default value of `type` being `:write`, a call to > `Mint.HTTP.open?(conn)` will return `false` if `conn` was closed for writing > but is still open for reading. If you need to make sure the connection is > completely closed, check that `Mint.HTTP.open?(conn, :read)` returns `false`. @@ -531,8 +531,8 @@ defmodule Mint.HTTP do """ @impl true - @spec open?(t(), :read | :write | :read_write) :: boolean() - def open?(conn, type \\ :read_write), do: conn_module(conn).open?(conn, type) + @spec open?(t(), :read | :write) :: boolean() + def open?(conn, type \\ :write), do: conn_module(conn).open?(conn, type) @doc """ Sends a request to the connected server. diff --git a/lib/mint/http1.ex b/lib/mint/http1.ex index 628b661b..18b2e2fc 100644 --- a/lib/mint/http1.ex +++ b/lib/mint/http1.ex @@ -231,9 +231,10 @@ defmodule Mint.HTTP1 do See `Mint.HTTP.open?/1`. """ @impl true - @spec open?(t(), :read | :write | :read_write) :: boolean() - def open?(conn, type \\ :read_write) + @spec open?(t(), :read | :write) :: boolean() + def open?(conn, type \\ :write) + # TODO: hard-deprecate :read_write in 1.7. def open?(%__MODULE__{state: state}, type) when type in [:read, :write, :read_write] do state == :open end diff --git a/lib/mint/http2.ex b/lib/mint/http2.ex index 9beaef0a..c12a88aa 100644 --- a/lib/mint/http2.ex +++ b/lib/mint/http2.ex @@ -448,8 +448,8 @@ defmodule Mint.HTTP2 do See `Mint.HTTP.open?/1`. """ @impl true - @spec open?(t(), :read | :write | :read_write) :: boolean() - def open?(%__MODULE__{state: state} = _conn, type \\ :read_write) + @spec open?(t(), :read | :write) :: boolean() + def open?(%__MODULE__{state: state} = _conn, type \\ :write) when type in [:read, :write, :read_write] do case state do :handshaking -> true diff --git a/lib/mint/unsafe_proxy.ex b/lib/mint/unsafe_proxy.ex index 21f8d17a..b6318ffa 100644 --- a/lib/mint/unsafe_proxy.ex +++ b/lib/mint/unsafe_proxy.ex @@ -58,8 +58,8 @@ defmodule Mint.UnsafeProxy do end @impl true - @spec open?(t(), :read | :write | :read_write) :: boolean() - def open?(%UnsafeProxy{module: module, state: state}, type \\ :read_write) do + @spec open?(t(), :read | :write) :: boolean() + def open?(%UnsafeProxy{module: module, state: state}, type \\ :write) do module.open?(state, type) end