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.
Here's the new function body:
bool done = false;
ScopedPointer<StringPairArray> currentResponseHeaders = new StringPairArray(false);
done = true;
DWORD bufferSizeBytes = 4096;
HeapBlock<char> buffer((size_t) bufferSizeBytes);
if (HttpQueryInfo(request, HTTP_QUERY_RAW_HEADERS_CRLF, buffer.getData(), &bufferSizeBytes, 0))
headersArray.addLines(String(reinterpret_cast<const WCHAR*> (buffer.getData())));
for (int i = 0; i < headersArray.size(); ++i)
const String& header = headersArray[i];
const String key(header.upToFirstOccurrenceOf(": ", false, false));
const String value(header.fromFirstOccurrenceOf(": ", false, false));
const String previousValue((*currentResponseHeaders)[key]);
currentResponseHeaders->set(key, previousValue.isEmpty() ? value : (previousValue + "," + value));
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
DWORD status = 0;
DWORD statusSize = sizeof(status);
if (HttpQueryInfo(request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &statusSize, 0))
statusCode = (int) status;
if (statusCode == 301 ||
statusCode == 302 ||
statusCode == 303 ||
statusCode == 307)
address = (*currentResponseHeaders)["Location"];
done = false;
Keep in mind:
- 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.