@@ -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 )
10661067end
0 commit comments