I also bumped into this problem, then searched for this thread and realized I should patch it until Jules fixes it.
All the changes are in juce_win32_Network.cpp::WebInputStream::WebInputStream(...):
I wrapped the code in a while statement, and as long as the returned status code was one of 301, 302, 303, 307, I would keep looping with the new address (Location parameter), if present. Else I would just end the loop and return.
I didn't test this thoroughly, I just made sure the redirection works.
I expect some funny callback behaviour, if supplied.
There's another redirection status code, 300, but I didn't find an example for it and I gather it's rather rare and complex, so I decided to neglect it.
I thought this was fine too, until I realised it broke something for me!
I've got a bit of code that attempts a login and looks for a Set-Cookie command in the response headers. The problem is that this appears only in the first response and this response is a redirect. So the new code automatically follows the redirect and gets a new set of response headers which no longer include the Set-Cookie command.
Suggested fix (which works for me):
add "const bool ignoreRedirects = false" to method signature for URL::createInputStream
add same parameter to the WebInputStream constructor and pass said parameter to WebInputStream wi object when it is created
change initialisation of maxRedirects in for loop to "int maxRedirects = ignoreRedirects ? 1 : 10"
change condition in status code check to "if (!ignoreRedirects && (status == 301 || status == 302 || status == 303 || status == 307))"
I haven't considered what this might mean for non Win32 implementations.
Another approach might be to accumulate header responses from all redirects but I shudder to think what might go wrong if you did that.
Well, assuming that the current implementation is now consitent across OSX and Windows, I could add a flag if you can let me know how that should be implemented on OSX - am too busy on other stuff to dig into it and research it myself this week..
Um well, I'm not sure if there's any consistency to start with.
Win32 code has just been changed from no redirects to max 10 redirects
Apple code doesn't retry the NSMutableURLRequest; but it looks like your delegate implementation allows following of 1 redirect (then again maybe it recurses infinitely, I'm not used to Objective-C and can't tell)
Linux code appears to handle max 3 redirects
Android code appears to use HttpURLConnection which handles up to 5 redirects
Jules - I'm not sure if you processed my previous post but I've been thinking there's a few ways to improve the consistency here:
Normalise to a max of 5 redirects across all platforms (presuming we can sort out Apple) and allow user to set ignoreRedirects (in which case Android will be an exception)
Allow user to specify the number of redirects they want to follow (again Android would be an exception)
Don't allow user to set ignoreRedirects, but record all response headers so they can be checked after the fact
If you can let me know which you'd prefer, I can see if I can get it working (might take me a while to sort the Apple one though).
PS - I notice you've got CloudFlare going on the website today - now I've got another cookie to intercept :)
Maybe if we can find a way on all the platforms to control the number of redirects, then instead of a bool to disable them, the user could supply the maximum number that should be allowed, and we could set it to 5 by default?