JUCE_USE_CURL Send back the cookies sent by the server on redirects

Hello,

Some sites require the client to send back the cookies sent by the server on redirects.

url in question:

fails

Setting curl_easy_setopt (curl, CURLOPT_COOKIEFILE, "") in juce_curl_Network.cpp WebInputStream::setOptions() fixes the issue.

https://curl.haxx.se/libcurl/c/CURLOPT_COOKIEFILE.html

Given an empty or non-existing file or by passing the empty string (“”) to this option, you can enable the cookie engine without reading any initial cookies.

Would this be a good thing to always enable?

@fabien I’m not sure…

I think one solution would be to provide some way to set additional curl options in the juce::URL class if JUCE_USE_CURL is enabled.

An optional key/value pair(s) that can be set before URL::createInputStream() is called. URL::createInputStream() can check the JUCE_USE_CURL flag and grab the additional settings/options set? But this seems kinda messy and you’d probably need to also provide a way to set NSURLConnection options at that point to make sure each OS has this option.

Reading the docs suggests that passing an empty string with CURLOPT_COOKIEFILE “enables the cookie engine”. I’d compare this to all the other platforms(s).

NSURLConnection has cookies enabled and the cookie engine is based on the settings for the device. The url I posted earlier works on Mac OSX without any special options set in juce_mac_Network IMPL so I’d expect the same result on the Linux side.

I don’t have a windows box unfortunately to see if the url works there.

OK I’ve added this to the develop branch. Thank you for reporting!

I believe I am having a similar issue:

  • I can retrieve information from an endpoint with a newly-made APIKey successfully
  • If I create a new APIKey and try to retrieve information not too long after the first time, I get error 401. This is regardless of if I am logging in to the same user.

The funny thing is that it does not happen from my browser, where the same APIKey that has got the 401, gets a 200. Additionally, it happens on iOS, MacOs, Windows and Android.

I believe cookies not being retrieved by the juce networking methods could be the issue. Has this been fixed?