0

I am having problems with proxy configuration in libcurl.

Using the same handle I want to download the same URL 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, "");

And setting it to something wrong before the second download: curl_easy_setopt(handle, CURLOPT_PROXY, "wrong:80");

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.

The weird thing is that 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 someone please help me figure out how is port 80 special and how can I reuse same libcurl handle so that without proxy download succeeds and with wrong proxy the download fails.

Thanks in advance

3
  • What kind of URL are you requesting? Are you using a single persistent connection for both requests? If so, the proxy may be getting ignored on the second request since the socket is still connected. Try disconnecting before sending the second request. See the CURLOPT_FRESH_CONNECT and CURLOPT_FORBID_REUSE options. Apr 19, 2016 at 22:18
  • Thanks for your response Remy. For testing purposes I am using microsoft.com URL. I also have an impression that the issue is related to reusing previous successfully established connection, because this issue happens only in case if successful download proceeds the trial with wrong proxy. However I just tried using the options you suggested but it didn't work with neither of the options. Still download was successful even with wrong proxy.
    – mkd156
    Apr 19, 2016 at 22:31
  • If this is with a recent libcurl, chances are you ran right into a regression we fixed here: github.com/curl/curl/commit/439afae886e10 Apr 29, 2016 at 8:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.