From 99d1357a4cf86ab011f40cc5f8d203a8127d4d09 Mon Sep 17 00:00:00 2001 From: jules Date: Thu, 19 Sep 2013 19:26:46 +0100 Subject: [PATCH] Added a "willSendRequest" callback to the OSX web stream delegate class. --- modules/juce_core/native/juce_mac_Network.mm | 36 +++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/modules/juce_core/native/juce_mac_Network.mm b/modules/juce_core/native/juce_mac_Network.mm index 9d38c36a71..55be8391bc 100644 --- a/modules/juce_core/native/juce_mac_Network.mm +++ b/modules/juce_core/native/juce_mac_Network.mm @@ -250,18 +250,19 @@ public: private: //============================================================================== - struct DelegateClass : public ObjCClass + struct DelegateClass : public ObjCClass { - DelegateClass() : ObjCClass ("JUCEAppDelegate_") + DelegateClass() : ObjCClass ("JUCEAppDelegate_") { - addIvar ("state"); + addIvar ("state"); - addMethod (@selector (connection:didReceiveResponse:), didReceiveResponse, "v@:@@"); - addMethod (@selector (connection:didFailWithError:), didFailWithError, "v@:@@"); - addMethod (@selector (connection:didReceiveData:), didReceiveData, "v@:@@"); + addMethod (@selector (connection:didReceiveResponse:), didReceiveResponse, "v@:@@"); + addMethod (@selector (connection:didFailWithError:), didFailWithError, "v@:@@"); + addMethod (@selector (connection:didReceiveData:), didReceiveData, "v@:@@"); addMethod (@selector (connection:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite:totalBytesExpectedToWrite:), - connectionDidSendBodyData, "v@:@iii"); - addMethod (@selector (connectionDidFinishLoading:), connectionDidFinishLoading, "v@:@"); + connectionDidSendBodyData, "v@:@iii"); + addMethod (@selector (connectionDidFinishLoading:), connectionDidFinishLoading, "v@:@"); + addMethod (@selector (connection:willSendRequest:redirectResponse:), willSendRequest, "@@:@@"); registerClass(); } @@ -285,6 +286,11 @@ private: getState (self)->didReceiveData (newData); } + static NSURLRequest* willSendRequest (id, SEL, NSURLConnection*, NSURLRequest* request, NSURLResponse*) + { + return request; + } + static void connectionDidSendBodyData (id self, SEL, NSURLConnection*, NSInteger, NSInteger totalBytesWritten, NSInteger totalBytesExpected) { getState (self)->didSendBodyData (totalBytesWritten, totalBytesExpected); @@ -317,9 +323,8 @@ public: if (responseHeaders != nullptr && connection != nullptr && connection->headers != nil) { NSEnumerator* enumerator = [connection->headers keyEnumerator]; - NSString* key; - while ((key = [enumerator nextObject]) != nil) + while (NSString* key = [enumerator nextObject]) responseHeaders->set (nsStringToJuce (key), nsStringToJuce ((NSString*) [connection->headers objectForKey: key])); } @@ -341,7 +346,7 @@ public: JUCE_AUTORELEASEPOOL { - const int bytesRead = connection->read (static_cast (buffer), bytesToRead); + const int bytesRead = connection->read (static_cast (buffer), bytesToRead); position += bytesRead; if (bytesRead == 0) @@ -379,8 +384,7 @@ private: const bool isPost; const int timeOutMs; - void createConnection (URL::OpenStreamProgressCallback* progressCallback, - void* progressCallbackContext) + void createConnection (URL::OpenStreamProgressCallback* progressCallback, void* progressCallbackContext) { jassert (connection == nullptr); @@ -424,9 +428,9 @@ InputStream* URL::createNativeStream (const String& address, bool isPost, const OpenStreamProgressCallback* progressCallback, void* progressCallbackContext, const String& headers, const int timeOutMs, StringPairArray* responseHeaders) { - ScopedPointer wi (new WebInputStream (address, isPost, postData, - progressCallback, progressCallbackContext, - headers, timeOutMs, responseHeaders)); + ScopedPointer wi (new WebInputStream (address, isPost, postData, + progressCallback, progressCallbackContext, + headers, timeOutMs, responseHeaders)); return wi->isError() ? nullptr : wi.release(); }