Skip to content

Commit 63ce63c

Browse files
authored
Fix warnings on Elixir v1.19 (#460)
1 parent 6b6f1d4 commit 63ce63c

File tree

3 files changed

+29
-28
lines changed

3 files changed

+29
-28
lines changed

lib/mint/http.ex

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ defmodule Mint.HTTP do
493493
"""
494494
@impl true
495495
@spec close(t()) :: {:ok, t()}
496-
def close(conn), do: conn_module(conn).close(conn)
496+
def close(conn), do: conn_apply(conn, :close, [conn])
497497

498498
@doc """
499499
Checks whether the connection is open.
@@ -530,7 +530,7 @@ defmodule Mint.HTTP do
530530
"""
531531
@impl true
532532
@spec open?(t(), :read | :write) :: boolean()
533-
def open?(conn, type \\ :write), do: conn_module(conn).open?(conn, type)
533+
def open?(conn, type \\ :write), do: conn_apply(conn, :open, [conn, type])
534534

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

601601
def request(conn, method, path, headers, body),
602-
do: conn_module(conn).request(conn, method, path, headers, body)
602+
do: conn_apply(conn, :request, [conn, method, path, headers, body])
603603

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

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

832832
@doc """
833833
Returns the number of open requests.
@@ -846,7 +846,7 @@ defmodule Mint.HTTP do
846846
"""
847847
@impl true
848848
@spec open_request_count(t()) :: non_neg_integer()
849-
def open_request_count(conn), do: conn_module(conn).open_request_count(conn)
849+
def open_request_count(conn), do: conn_apply(conn, :open_request_count, [conn])
850850

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

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

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

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

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

10001001
@doc """
10011002
Deletes a value in the private store.
@@ -1019,7 +1020,7 @@ defmodule Mint.HTTP do
10191020
"""
10201021
@impl true
10211022
@spec delete_private(t(), atom()) :: t()
1022-
def delete_private(conn, key), do: conn_module(conn).delete_private(conn, key)
1023+
def delete_private(conn, key), do: conn_apply(conn, :delete_private, [conn, key])
10231024

10241025
@doc """
10251026
Gets the socket associated with the connection.
@@ -1030,7 +1031,7 @@ defmodule Mint.HTTP do
10301031
"""
10311032
@impl true
10321033
@spec get_socket(t()) :: Mint.Types.socket()
1033-
def get_socket(conn), do: conn_module(conn).get_socket(conn)
1034+
def get_socket(conn), do: conn_apply(conn, :get_socket, [conn])
10341035

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

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

10561057
# Made public since the struct is opaque.
10571058
@doc false
10581059
@impl true
1059-
def put_proxy_headers(conn, headers), do: conn_module(conn).put_proxy_headers(conn, headers)
1060+
def put_proxy_headers(conn, headers), do: conn_apply(conn, :put_proxy_headers, [conn, headers])
10601061

10611062
## Helpers
10621063

1063-
defp conn_module(%UnsafeProxy{}), do: UnsafeProxy
1064-
defp conn_module(%Mint.HTTP1{}), do: Mint.HTTP1
1065-
defp conn_module(%Mint.HTTP2{}), do: Mint.HTTP2
1064+
defp conn_apply(%UnsafeProxy{}, fun, args), do: apply(UnsafeProxy, fun, args)
1065+
defp conn_apply(%Mint.HTTP1{}, fun, args), do: apply(Mint.HTTP1, fun, args)
1066+
defp conn_apply(%Mint.HTTP2{}, fun, args), do: apply(Mint.HTTP2, fun, args)
10661067
end

lib/mint/http1.ex

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ defmodule Mint.HTTP1 do
295295

296296
case request.state do
297297
{:stream_request, _} ->
298-
conn = %__MODULE__{conn | streaming_request: request}
298+
conn = %{conn | streaming_request: request}
299299
{:ok, conn, request_ref}
300300

301301
_ ->
@@ -351,7 +351,7 @@ defmodule Mint.HTTP1 do
351351
:eof
352352
) do
353353
request = %{conn.streaming_request | state: :status}
354-
conn = enqueue_request(%__MODULE__{conn | streaming_request: nil}, request)
354+
conn = enqueue_request(%{conn | streaming_request: nil}, request)
355355
{:ok, conn}
356356
end
357357

@@ -390,12 +390,12 @@ defmodule Mint.HTTP1 do
390390
case chunk do
391391
:eof ->
392392
request = %{conn.streaming_request | state: :status}
393-
conn = enqueue_request(%__MODULE__{conn | streaming_request: nil}, request)
393+
conn = enqueue_request(%{conn | streaming_request: nil}, request)
394394
{:ok, conn}
395395

396396
{:eof, _trailer_headers} ->
397397
request = %{conn.streaming_request | state: :status}
398-
conn = enqueue_request(%__MODULE__{conn | streaming_request: nil}, request)
398+
conn = enqueue_request(%{conn | streaming_request: nil}, request)
399399
{:ok, conn}
400400

401401
_other ->
@@ -639,7 +639,7 @@ defmodule Mint.HTTP1 do
639639
@impl true
640640
@spec put_proxy_headers(t(), Mint.Types.headers()) :: t()
641641
def put_proxy_headers(%__MODULE__{} = conn, headers) when is_list(headers) do
642-
%__MODULE__{conn | proxy_headers: headers}
642+
%{conn | proxy_headers: headers}
643643
end
644644

645645
## Helpers
@@ -918,12 +918,12 @@ defmodule Mint.HTTP1 do
918918
end
919919

920920
defp enqueue_request(%{request: nil} = conn, request) do
921-
%__MODULE__{conn | request: request}
921+
%{conn | request: request}
922922
end
923923

924924
defp enqueue_request(conn, request) do
925925
requests = :queue.in(request, conn.requests)
926-
%__MODULE__{conn | requests: requests}
926+
%{conn | requests: requests}
927927
end
928928

929929
defp internal_close(conn) do

lib/mint/http2.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ defmodule Mint.HTTP2 do
10361036
@doc false
10371037
@impl true
10381038
def put_proxy_headers(%__MODULE__{} = conn, headers) when is_list(headers) do
1039-
%__MODULE__{conn | proxy_headers: headers}
1039+
%{conn | proxy_headers: headers}
10401040
end
10411041

10421042
## Helpers
@@ -1467,7 +1467,7 @@ defmodule Mint.HTTP2 do
14671467
send_connection_error!(conn, :protocol_error, debug_data)
14681468

14691469
conn.state == :handshaking ->
1470-
%__MODULE__{conn | state: :open}
1470+
%{conn | state: :open}
14711471

14721472
true ->
14731473
conn

0 commit comments

Comments
 (0)