@@ -492,7 +492,8 @@ proxy_integration_test_() ->
492492 [
493493 {" HTTP CONNECT proxy to HTTP target" , {timeout , 30 , fun () -> test_connect_proxy_http (State ) end }},
494494 {" SOCKS5 proxy to HTTP target" , {timeout , 30 , fun () -> test_socks5_proxy_http (State ) end }},
495- {" Simple HTTP proxy to HTTP target" , {timeout , 30 , fun () -> test_http_proxy (State ) end }}
495+ {" Simple HTTP proxy to HTTP target" , {timeout , 30 , fun () -> test_http_proxy (State ) end }},
496+ {" Proxy config preserved during redirect" , {timeout , 30 , fun () -> test_proxy_with_redirect (State ) end }}
496497 ]
497498 end }.
498499
@@ -568,6 +569,30 @@ test_http_proxy(#{http_proxy := {_, ProxyPort}}) ->
568569 error ({http_proxy_failed , Reason })
569570 end .
570571
572+ test_proxy_with_redirect (#{http_proxy := {_ , ProxyPort }}) ->
573+ % % Test that proxy configuration is preserved during redirects
574+ % % Request a URL that triggers a redirect, and verify the redirect
575+ % % is followed successfully through the proxy
576+ RedirectTarget = iolist_to_binary ([<<" http://127.0.0.1:" >>, integer_to_binary (? TEST_PORT ), <<" /get" >>]),
577+ Url = iolist_to_binary ([<<" http://127.0.0.1:" >>, integer_to_binary (? TEST_PORT ),
578+ <<" /redirect-to?url=" >>, RedirectTarget ]),
579+ Options = [
580+ {proxy , {" 127.0.0.1" , ProxyPort }},
581+ {follow_redirect , true },
582+ {recv_timeout , 10000 },
583+ with_body
584+ ],
585+ case hackney :request (get , Url , [], <<>>, Options ) of
586+ {ok , 200 , _Headers , Body } ->
587+ % % If we got 200, the redirect was followed successfully through the proxy
588+ ? assert (byte_size (Body ) > 0 );
589+ {ok , Status , _Headers , _Body } ->
590+ error ({unexpected_status , Status });
591+ {error , Reason } ->
592+ ct :pal (" Proxy with redirect failed: ~p~n " , [Reason ]),
593+ error ({proxy_redirect_failed , Reason })
594+ end .
595+
571596% % Test proxy via environment variable
572597env_var_proxy_test_ () ->
573598 {setup ,
0 commit comments