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

Fix warnings on Elixir v1.19 #460

Merged
merged 1 commit into from
Jan 27, 2025
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
39 changes: 20 additions & 19 deletions lib/mint/http.ex
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ defmodule Mint.HTTP do
"""
@impl true
@spec close(t()) :: {:ok, t()}
def close(conn), do: conn_module(conn).close(conn)
def close(conn), do: conn_apply(conn, :close, [conn])

@doc """
Checks whether the connection is open.
Expand Down Expand Up @@ -530,7 +530,7 @@ defmodule Mint.HTTP do
"""
@impl true
@spec open?(t(), :read | :write) :: boolean()
def open?(conn, type \\ :write), do: conn_module(conn).open?(conn, type)
def open?(conn, type \\ :write), do: conn_apply(conn, :open, [conn, type])

@doc """
Sends a request to the connected server.
Expand Down Expand Up @@ -599,7 +599,7 @@ defmodule Mint.HTTP do
| {:error, t(), Types.error()}

def request(conn, method, path, headers, body),
do: conn_module(conn).request(conn, method, path, headers, body)
do: conn_apply(conn, :request, [conn, method, path, headers, body])

@doc """
Streams a chunk of the request body on the connection or signals the end of the body.
Expand Down Expand Up @@ -690,7 +690,7 @@ defmodule Mint.HTTP do
) ::
{:ok, t()} | {:error, t(), Types.error()}
def stream_request_body(conn, ref, body),
do: conn_module(conn).stream_request_body(conn, ref, body)
do: conn_apply(conn, :stream_request_body, [conn, ref, body])

@doc """
Streams the next batch of responses from the given `message`.
Expand Down Expand Up @@ -827,7 +827,7 @@ defmodule Mint.HTTP do
{:ok, t(), [Types.response()]}
| {:error, t(), Types.error(), [Types.response()]}
| :unknown
def stream(conn, message), do: conn_module(conn).stream(conn, message)
def stream(conn, message), do: conn_apply(conn, :stream, [conn, message])

@doc """
Returns the number of open requests.
Expand All @@ -846,7 +846,7 @@ defmodule Mint.HTTP do
"""
@impl true
@spec open_request_count(t()) :: non_neg_integer()
def open_request_count(conn), do: conn_module(conn).open_request_count(conn)
def open_request_count(conn), do: conn_apply(conn, :open_request_count, [conn])

@doc """
Receives data from the socket in a blocking way.
Expand Down Expand Up @@ -882,7 +882,7 @@ defmodule Mint.HTTP do
@spec recv(t(), non_neg_integer(), timeout()) ::
{:ok, t(), [Types.response()]}
| {:error, t(), Types.error(), [Types.response()]}
def recv(conn, byte_count, timeout), do: conn_module(conn).recv(conn, byte_count, timeout)
def recv(conn, byte_count, timeout), do: conn_apply(conn, :recv, [conn, byte_count, timeout])

@doc """
Changes the mode of the underlying socket.
Expand All @@ -908,7 +908,7 @@ defmodule Mint.HTTP do
"""
@impl true
@spec set_mode(t(), :active | :passive) :: {:ok, t()} | {:error, Types.error()}
def set_mode(conn, mode), do: conn_module(conn).set_mode(conn, mode)
def set_mode(conn, mode), do: conn_apply(conn, :set_mode, [conn, mode])

@doc """
Changes the *controlling process* of the given connection to `new_pid`.
Expand Down Expand Up @@ -946,7 +946,8 @@ defmodule Mint.HTTP do
"""
@impl true
@spec controlling_process(t(), pid()) :: {:ok, t()} | {:error, Types.error()}
def controlling_process(conn, new_pid), do: conn_module(conn).controlling_process(conn, new_pid)
def controlling_process(conn, new_pid),
do: conn_apply(conn, :controlling_process, [conn, new_pid])

@doc """
Assigns a new private key and value in the connection.
Expand All @@ -970,7 +971,7 @@ defmodule Mint.HTTP do
"""
@impl true
@spec put_private(t(), atom(), term()) :: t()
def put_private(conn, key, value), do: conn_module(conn).put_private(conn, key, value)
def put_private(conn, key, value), do: conn_apply(conn, :put_private, [conn, key, value])

@doc """
Gets a private value from the connection.
Expand All @@ -995,7 +996,7 @@ defmodule Mint.HTTP do
@impl true
@spec get_private(t(), atom(), term()) :: term()
def get_private(conn, key, default \\ nil),
do: conn_module(conn).get_private(conn, key, default)
do: conn_apply(conn, :get_private, [conn, key, default])

@doc """
Deletes a value in the private store.
Expand All @@ -1019,7 +1020,7 @@ defmodule Mint.HTTP do
"""
@impl true
@spec delete_private(t(), atom()) :: t()
def delete_private(conn, key), do: conn_module(conn).delete_private(conn, key)
def delete_private(conn, key), do: conn_apply(conn, :delete_private, [conn, key])

@doc """
Gets the socket associated with the connection.
Expand All @@ -1030,7 +1031,7 @@ defmodule Mint.HTTP do
"""
@impl true
@spec get_socket(t()) :: Mint.Types.socket()
def get_socket(conn), do: conn_module(conn).get_socket(conn)
def get_socket(conn), do: conn_apply(conn, :get_socket, [conn])

@doc """
Sets whether the connection should log information or not.
Expand All @@ -1040,7 +1041,7 @@ defmodule Mint.HTTP do
@doc since: "1.5.0"
@impl true
@spec put_log(t(), boolean()) :: t()
def put_log(conn, log?), do: conn_module(conn).put_log(conn, log?)
def put_log(conn, log?), do: conn_apply(conn, :put_log, [conn, log?])

@doc """
Gets the proxy headers associated with the connection in the `CONNECT` method.
Expand All @@ -1051,16 +1052,16 @@ defmodule Mint.HTTP do
@doc since: "1.4.0"
@impl true
@spec get_proxy_headers(t()) :: Mint.Types.headers()
def get_proxy_headers(conn), do: conn_module(conn).get_proxy_headers(conn)
def get_proxy_headers(conn), do: conn_apply(conn, :get_proxy_headers, [conn])

# Made public since the struct is opaque.
@doc false
@impl true
def put_proxy_headers(conn, headers), do: conn_module(conn).put_proxy_headers(conn, headers)
def put_proxy_headers(conn, headers), do: conn_apply(conn, :put_proxy_headers, [conn, headers])

## Helpers

defp conn_module(%UnsafeProxy{}), do: UnsafeProxy
defp conn_module(%Mint.HTTP1{}), do: Mint.HTTP1
defp conn_module(%Mint.HTTP2{}), do: Mint.HTTP2
defp conn_apply(%UnsafeProxy{}, fun, args), do: apply(UnsafeProxy, fun, args)
defp conn_apply(%Mint.HTTP1{}, fun, args), do: apply(Mint.HTTP1, fun, args)
defp conn_apply(%Mint.HTTP2{}, fun, args), do: apply(Mint.HTTP2, fun, args)
end
14 changes: 7 additions & 7 deletions lib/mint/http1.ex
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ defmodule Mint.HTTP1 do

case request.state do
{:stream_request, _} ->
conn = %__MODULE__{conn | streaming_request: request}
conn = %{conn | streaming_request: request}
{:ok, conn, request_ref}

_ ->
Expand Down Expand Up @@ -351,7 +351,7 @@ defmodule Mint.HTTP1 do
:eof
) do
request = %{conn.streaming_request | state: :status}
conn = enqueue_request(%__MODULE__{conn | streaming_request: nil}, request)
conn = enqueue_request(%{conn | streaming_request: nil}, request)
{:ok, conn}
end

Expand Down Expand Up @@ -390,12 +390,12 @@ defmodule Mint.HTTP1 do
case chunk do
:eof ->
request = %{conn.streaming_request | state: :status}
conn = enqueue_request(%__MODULE__{conn | streaming_request: nil}, request)
conn = enqueue_request(%{conn | streaming_request: nil}, request)
{:ok, conn}

{:eof, _trailer_headers} ->
request = %{conn.streaming_request | state: :status}
conn = enqueue_request(%__MODULE__{conn | streaming_request: nil}, request)
conn = enqueue_request(%{conn | streaming_request: nil}, request)
{:ok, conn}

_other ->
Expand Down Expand Up @@ -639,7 +639,7 @@ defmodule Mint.HTTP1 do
@impl true
@spec put_proxy_headers(t(), Mint.Types.headers()) :: t()
def put_proxy_headers(%__MODULE__{} = conn, headers) when is_list(headers) do
%__MODULE__{conn | proxy_headers: headers}
%{conn | proxy_headers: headers}
end

## Helpers
Expand Down Expand Up @@ -918,12 +918,12 @@ defmodule Mint.HTTP1 do
end

defp enqueue_request(%{request: nil} = conn, request) do
%__MODULE__{conn | request: request}
%{conn | request: request}
end

defp enqueue_request(conn, request) do
requests = :queue.in(request, conn.requests)
%__MODULE__{conn | requests: requests}
%{conn | requests: requests}
end

defp internal_close(conn) do
Expand Down
4 changes: 2 additions & 2 deletions lib/mint/http2.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ defmodule Mint.HTTP2 do
@doc false
@impl true
def put_proxy_headers(%__MODULE__{} = conn, headers) when is_list(headers) do
%__MODULE__{conn | proxy_headers: headers}
%{conn | proxy_headers: headers}
end

## Helpers
Expand Down Expand Up @@ -1467,7 +1467,7 @@ defmodule Mint.HTTP2 do
send_connection_error!(conn, :protocol_error, debug_data)

conn.state == :handshaking ->
%__MODULE__{conn | state: :open}
%{conn | state: :open}

true ->
conn
Expand Down
Loading