Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate :read_write option on HTTP.open?/2 #426

Merged
merged 2 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -503,16 +503,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 @@ -525,8 +525,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
ericmj marked this conversation as resolved.
Show resolved Hide resolved
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
Loading