Hello Jules, I’ve added this new feature. I wanted to attach the resulting .patch file to this message but unfortunately it does not seem to allow the attachment of files with extensions patch, diff or even txt, so I’m pasting it here. Hope you will be able to use it anyway. If not, contact me and I’ll send it over again, maybe by email.
[code]diff --git a/src/io/network/juce_URL.cpp b/src/io/network/juce_URL.cpp
index 406b26b…700ffa6 100644
— a/src/io/network/juce_URL.cpp
+++ b/src/io/network/juce_URL.cpp
@@ -244,6 +244,8 @@ void juce_closeInternetFile (void* handle);
int juce_readFromInternetFile (void* handle, void* dest, int bytesToRead);
int juce_seekInInternetFile (void* handle, int newPosition);
int64 juce_getInternetFileContentLength (void* handle);
+bool juce_getInternetFileHeaders (void* handle, StringPairArray* headers);
+
//==============================================================================
@@ -256,7 +258,8 @@ public:
URL::OpenStreamProgressCallback* const progressCallback_,
void* const progressCallbackContext_,
const String& extraHeaders,
@@ -277,6 +280,9 @@ public:
handle = juce_openInternetFile (server, headers, postData, isPost,
progressCallback_, progressCallbackContext_,
timeOutMs);
+
-
if (responseHeaders != 0)
-
juce_getInternetFileHeaders (handle, responseHeaders);
}
~WebInputStream()
@@ -419,12 +425,14 @@ InputStream* URL::createInputStream (const bool usePostCommand,
OpenStreamProgressCallback* const progressCallback,
void* const progressCallbackContext,
const String& extraHeaders,
{
ScopedPointer wi (new WebInputStream (*this, usePostCommand,
progressCallback, progressCallbackContext,
extraHeaders,
-
timeOutMs,
-
responseHeaders));
return wi->isError() ? 0 : wi.release();
}
diff --git a/src/io/network/juce_URL.h b/src/io/network/juce_URL.h
index f54c22f…3d3ed9b 100644
— a/src/io/network/juce_URL.h
+++ b/src/io/network/juce_URL.h
@@ -203,12 +203,15 @@ public:
@param connectionTimeOutMs if 0, this will use whatever default setting the OS chooses. If
a negative number, it will be infinite. Otherwise it specifies a
time in milliseconds.
-
@param responseHeaders if this is non-zero, all the (key, value) pairs received as headers
-
in the response will be stored in this array
-
*/
InputStream* createInputStream (bool usePostCommand,
OpenStreamProgressCallback* progressCallback = 0,
void* progressCallbackContext = 0,
const String& extraHeaders = String::empty,
-
int connectionTimeOutMs = 0,
-
StringPairArray* responseHeaders = 0) const;
//==============================================================================
diff --git a/src/native/mac/juce_mac_Network.mm b/src/native/mac/juce_mac_Network.mm
index a7d0170…d115188 100644
— a/src/native/mac/juce_mac_Network.mm
+++ b/src/native/mac/juce_mac_Network.mm
@@ -137,6 +137,7 @@ using namespace JUCE_NAMESPACE;
bool initialised, hasFailed, hasFinished;
int position;
int64 contentLength;
-
NSDictionary* allHeaders;
NSLock* dataLock;
}
@@ -200,6 +201,7 @@ public:
hasFailed = false;
hasFinished = false;
contentLength = -1;
@@ -244,6 +248,17 @@ public:
[dataLock unlock];
initialised = true;
contentLength = [response expectedContentLength];
+
}
- (void) connection: (NSURLConnection*) conn didFailWithError: (NSError*) error
@@ -416,6 +431,30 @@ int64 juce_getInternetFileContentLength (void* handle)
return -1;
}
+bool juce_getInternetFileHeaders (void* handle, StringPairArray* headers)
+{
- JuceURLConnection* const s = (JuceURLConnection*) handle;
- NSDictionary* dictionary = s->allHeaders;
-
- if (s != 0 && dictionary != 0)
- {
-
NSEnumerator* enumerator = [dictionary keyEnumerator];
-
id key;
-
-
while ((key = [enumerator nextObject]))
-
{
-
String keyString (nsStringToJuce ((NSString*)key));
-
String valueString (nsStringToJuce ((NSString*)[dictionary objectForKey:key]));
-
headers->set (keyString, valueString);
-
}
-
-
return true;
- }
-
- return false;
+}
-
-
int juce_seekInInternetFile (void* handle, int /newPosition/)
{
JuceURLConnection* const s = (JuceURLConnection*) handle;
diff --git a/src/native/windows/juce_win32_Network.cpp b/src/native/windows/juce_win32_Network.cpp
index 6073327…c4e9fc9 100644
— a/src/native/windows/juce_win32_Network.cpp
+++ b/src/native/windows/juce_win32_Network.cpp
@@ -279,6 +279,68 @@ int64 juce_getInternetFileContentLength (void* handle)
return -1;
}
+bool juce_getInternetFileHeaders (void* handle, StringPairArray* headers)
+{
- const ConnectionAndRequestStruct* const crs = static_cast <ConnectionAndRequestStruct*> (handle);
-
- if (crs != 0)
- {
-
LPVOID outputBuffer = 0;
-
DWORD size = 0;
-
-
// Implementation adapted from: http://msdn.microsoft.com/en-us/library/aa385373%28v=VS.85%29.aspx
-
-
for (;;) // Dummy loop for reiterating the call, because the first one will fail for insufficient buffer size.
-
{
-
if (! HttpQueryInfo (crs->request, HTTP_QUERY_RAW_HEADERS_CRLF, outputBuffer, &size, 0))
-
{
-
if (GetLastError () == ERROR_HTTP_HEADER_NOT_FOUND)
-
{
-
return true; // No header was present, this call returns successfully
-
}
-
else
-
{
-
if (GetLastError () == ERROR_INSUFFICIENT_BUFFER) // This is the expected result of the first call to HttpQueryInfo
-
{
-
jassert (outputBuffer == 0); // If this assert is triggered, we've looped more than once, and that's bad
-
outputBuffer = new char [size]; // Allocate the necessary buffer
-
continue; // Repeat the query
-
}
-
else // Unexpected error
-
{
-
if (outputBuffer)
-
delete [] outputBuffer;
-
return false;
-
}
-
}
-
}
-
-
// On success, here we should parse the received headers
-
String headersString ((wchar_t *) outputBuffer);
-
delete [] outputBuffer;
-
-
StringArray headersArray;
-
headersArray.addLines (headersString);
-
-
for (int i = 0; i < headersArray.size (); ++i)
-
{
-
const String& headersEntry = headersArray [i];
-
-
String key (headersEntry.upToFirstOccurrenceOf (": ", false, false));
-
String value (headersEntry.fromFirstOccurrenceOf (": ", false, false));
-
String previousValue ((*headers) [key]);
-
-
headers->set (key, previousValue.isEmpty () ? value : previousValue + ";" + value);
-
}
-
-
return true;
-
}
- }
-
- return false;
+}
-
-
void juce_closeInternetFile (void* handle)
{
if (handle != 0)
[/code]