@@ -174,7 +174,7 @@ handle_call({send_req, _}, _From, #state{is_closing = true} = State) ->
174
174
{reply , {error , connection_closing }, State };
175
175
176
176
handle_call ({send_req , _ }, _From , # state {proc_state = ? dead_proc_walking } = State ) ->
177
- shutting_down (State ),
177
+ shutting_down (State ),
178
178
{reply , {error , connection_closing }, State };
179
179
180
180
handle_call ({send_req , {Url , Headers , Method , Body , Options , Timeout }},
@@ -571,21 +571,28 @@ do_connect(Host, Port, Options, #state{is_ssl = true,
571
571
use_proxy = false ,
572
572
ssl_options = SSLOptions },
573
573
Timeout ) ->
574
- Socks5Host = get_value (socks5_host , Options , undefined ),
575
- Sock_options = get_sock_options (Host , Options , []),
576
- Conn = case Socks5Host of
577
- undefined ->
578
- gen_tcp :connect (Host , Port , Sock_options , Timeout );
579
- _ ->
580
- catch ibrowse_socks5 :connect (Host , Port , Options , Sock_options , Timeout )
581
- end ,
582
- case Conn of
583
- {ok , Sock } ->
584
- ssl :connect (Sock , SSLOptions , Timeout );
585
- _ ->
586
- error
574
+ % % if a socks5 proxy is configured, open the socket separately
575
+ % % before upgrading the socket to a TLS connection.
576
+ case get_value (socks5_host , Options , undefined ) of
577
+ % % no socks5 proxy is configured, connect directly with TLS:
578
+ undefined ->
579
+ Sock_options = get_sock_options (Host , Options , SSLOptions ),
580
+ ssl :connect (Host , Port , Sock_options , Timeout );
581
+
582
+ % % proxy configuration is present: first establish a socket
583
+ % % and then upgrade:
584
+ _ ->
585
+ Sock_options = get_sock_options (Host , Options , []),
586
+ Conn = ibrowse_socks5 :connect (Host , Port , Options ,
587
+ Sock_options , Timeout ),
588
+ case Conn of
589
+ {ok , Sock } ->
590
+ ssl :connect (Sock , SSLOptions , Timeout );
591
+ _ ->
592
+ error
593
+ end
587
594
end ;
588
-
595
+
589
596
do_connect (Host , Port , Options , _State , Timeout ) ->
590
597
Socks5Host = get_value (socks5_host , Options , undefined ),
591
598
Sock_options = get_sock_options (Host , Options , []),
@@ -1918,7 +1925,7 @@ format_response_data(Resp_format, Body) ->
1918
1925
1919
1926
% % dont message an unexisting server
1920
1927
% % triggered by :stop or :tcp_closed on an unactive connection
1921
- do_reply (State , undefined , undefined , _ , _ , _Msg ) ->
1928
+ do_reply (State , undefined , undefined , _ , _ , _Msg ) ->
1922
1929
dec_pipeline_counter (State );
1923
1930
1924
1931
do_reply (State , From , undefined , _ , Resp_format , {ok , St_code , Headers , Body }) ->
0 commit comments