cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Proxy changes between transfers doesn't take effect immediately when using same handle

From: Ray Satiro via curl-library <curl-library_at_cool.haxx.se>
Date: Sat, 23 Apr 2016 02:55:52 -0400

On 4/22/2016 4:16 PM, BoBo via curl-library wrote:
> Hi.
>
> Using the same handle I want to download the same URL (e.g.
> microsoft.com <http://www.microsoft.com/>) first time without proxy
> and second time with wrong proxy.
>
> In order to achieve that I am setting proxy to empty string before the
> first download:
> curl_easy_setopt(handle, CURLOPT_PROXY, "");
> curl_easy_perform(handle);
>
> And setting it to something wrong before the second download:
> curl_easy_setopt(handle, CURLOPT_PROXY, "wrong:80");
> curl_easy_perform(handle);
>
> The expected correct result would be to succeed for the first time,
> and to fail for the second time, because the second download is using
> wrong proxy.
>
> But the actual result I am seeing is successful downloads for both
> cases. So I have the impression that although I am changing proxy
> option before triggering second transfer, the second transfer reuses
> the successfully established connection (one without proxy) instead of
> trying to create a new connection with new proxy information.
> I have also tried with CURLOPT_FRESH_CONNECT and CURLOPT_FORBID_REUSE
> options but didn't observe any change in
> behavior.<http://stackoverflow.com/questions/36730394/libcurl-disabling-proxy-when-using-same-handle#comment61044727_36730394>
>
> Two observations that I have made are:
>
> 1. If instead of immediately triggering the second download I wait for
> 2 minutes and only then trigger the second download with wrong proxy,
> the behavior is as expected (the second download fails).
> 2. This issue occurs only when my wrong proxy address has port 80
> (somewrongproxy:80). If I specify wrong proxy with port other than 80,
> everything works as expected.
>
> So can you please help me figure out how is port 80 special in this
> case and how I can reuse same libcurl handle so that proxy changes
> between transfers take effect.
>

curl -v http://test.com --next -x wrong:80 http://test.com
curl -v http://test.com --next -x wrong:81 http://test.com

I think the reason it fails when 81 is because it's looking in the DNS
cache for test.com port 81 and sees it doesn't exist whereas test.com
port 80 exists.

CURLM_STATE_WAITRESOLVE in the state machine has [1]:

   dns = Curl_fetch_addr(conn, conn->host.name, (int)conn->port);

But shouldn't that be conn->remote_port ?

And none of this explains why for wrong:80 it connects to test.com:80 as
if it's the proxy.

[1]: https://github.com/curl/curl/blob/curl-7_48_0/lib/multi.c#L1168-L1175

-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2016-04-23