Skip to content

Commit

Permalink
Deprecate :read_write option on HTTP.open?/2 (#426)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmj committed Feb 13, 2024
1 parent 23b431b commit 530ba27
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/mint/core/conn.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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()}

Expand Down
10 changes: 5 additions & 5 deletions lib/mint/http.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions lib/mint/http1.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/mint/http2.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/mint/unsafe_proxy.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 530ba27

Please sign in to comment.